当我执行以下操作时:
count = 0
while True:
count += 1
try:
print count
except IOError:
print 'cannot open'
这将打印0、1、2等。。一如预期。{1}虽然在下面的示例中执行了^ twisted,但仍中断了^执行的python循环。我错过了什么吗?在
^{pr2}$打印如下:
('bytesread read: ', 'The Fascin')
('count read: ', 1)
('task? : ', 'The Fascin')
Task 2: got 10 bytes of poetry from 127.0.0.1:10001
('bytesread read: ', 'The Ecstasy\n\nWhere, like a pil')
('count read: ', 1)
('task? : ', 'The Ecstasy\n\nWhere, like a pil')
Task 1: got 30 bytes of poetry from 127.0.0.1:10000
('bytesread read: ', 'Sonnet - T')
('count read: ', 1)
('task? : ', 'Sonnet - T')
Task 3: got 10 bytes of poetry from 127.0.0.1:10002
('bytesread read: ', 'low on a bed\n A pregna')
('count read: ', 1)
('task? : ', 'low on a bed\n A pregna')
Task 1: got 30 bytes of poetry from 127.0.0.1:10000
('bytesread read: ', 'ation of w')
('count read: ', 1)
('task? : ', 'ation of w')
Task 2: got 10 bytes of poetry from 127.0.0.1:10001
('bytesread read: ', 'o Science\n')
('count read: ', 1)
('task? : ', 'o Science\n')
Task 3: got 10 bytes of poetry from 127.0.0.1:10002
('bytesread read: ', "nt bank swell'd up to rest\nThe")
('count read: ', 1)
sock.recv()
返回EOF上的''
,因此如果套接字的远程端关闭文件,它将立即退出循环。在相关问题 更多 >
编程相关推荐