[Fwd: Re: [Tutor] What am I missing?]

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Sep 27 09:33:30 CEST 2004


> The blocking stuff that I mentioned in the previous mail is one
> additional complication.  Usually people don't have to worry about
> blocking issues at all.  But it applies to your situation because you're
> dealing with an external process ("tail -f") that just won't terminate.
> In that case, we have to do a bit extra to make things work right.

Hi Tom,


Sorry about emailing you again; I just keep screwing up.  *grin*

I just realized that the blocking stuff actually is fine, as long as we
stick with readline() instead of read().  So the code I sent can be
simplified to:

###
import os
import sys

if __name__ == '__main__':
    f = os.popen("tail -f %r" % sys.argv[1])
    while True:
        print "next line:",
        print f.readline()
###

If we exhaust the content of 'f', then the call to:

    f.readline()

blocks.  But this is fine, since it'll unblock itself as soon as a new
line of output shows up in the system log.  Things all work out fine
because we're dealing with text files.


I guess I'm trying to say: forget everything I said about the blocking
stuff.  *grin* It's more applicable when we have to do more complicated
stuff, but your filtering problem shouldn't need it.


Again, my apologies: my problem is that I see complicated solutions first.
Too much college, I think.  *grin* Anyway, I hope this helps!



More information about the Tutor mailing list