Unix Device File Emulation
A.T.Hofkamp
hat at se-162.se.wtb.tue.nl
Thu Apr 24 03:38:16 EDT 2008
On 2008-04-23, blaine <frikker at gmail.com> wrote:
> On Apr 23, 2:01 pm, "Martin Blume" <mbl... at freesurf.ch> wrote:
>> "blaine" schrieb
>> No,
>> while 1:
>> r = self.fifodev.readline()
>> if r: print r
>> else: time.sleep(0.1)
>> is ok (note the "if r:" clause).
>>
>> Martin
>
> Beautiful! Thanks Martin!
yes, but you have to follow the usual file handling rules, and close/re-open
the fifo after detecting EOF. You will be blocked on attempting to re-open
until there is another writing process.
while 1:
fp = open('my_fifo', 'r')
while 1:
line = fp.readline()
if line == '':
break
print line.rstrip() # To prevent printing of \n in line
fp.close()
Albert
More information about the Python-list
mailing list