Unix Device File Emulation

blaine frikker at gmail.com
Fri Apr 25 10:14:53 EDT 2008


On Apr 24, 3:38 am, "A.T.Hofkamp" <h... at se-162.se.wtb.tue.nl> wrote:
> On 2008-04-23, blaine <frik... 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

Oh, good call. Thanks a lot, that really helps.  I felt that the
previous solution was workable, but not perhaps 100% correct.

Thanks Albert!



More information about the Python-list mailing list