Blocking readline() Call?
peter at engcorp.com
Mon Nov 10 21:15:57 CET 2003
Scott Brady Drummonds wrote:
> I'm just figuring Python out but have become stalled with the following
> snippit of code: For some reason, the program stalls after the "read line:
> x" for the last line. The 'done reading cycle map' message is never
> while 1:
> line = file.readline()
> if line == '':
Correct this: you want "break", not continue.
> data = line.strip().split(':')
> cycleMap[int(data)] = int(data)
> i = i + 1
> print ('read line %d' % i)
> print ('done reading cycle map')
> I thought readline() was supposed to be non-blocking. Have I misunderstood
Yes, the problem wasn't where you thought it was. A well-placed print
statement or two would have showed you that readline was being called
repeatedly, not blocking.
More information about the Python-list