[Twisted-Python] suggestions needed on a process output event

Glyph Lefkowitz glyph at twistedmatrix.com
Wed Aug 13 01:16:10 EDT 2003


On Wednesday, August 13, 2003, at 12:05 AM, Itamar Shtull-Trauring 
wrote:

>> 2. How to add some special event? For example, I have a process
>> running: say "tail -f /var/log/messages". I wish, each time, when the
>> process outputs a new line, my protocol could receive such an event
>> (like dataReceived), and I can get that new line as my data. How to
>> implement this?
>
> reactor.spawnProcess, with a twisted.protocols.basic.LineReceiver 
> hooked
> up to the process. See http://twistedmatrix.com/documents/howto/process

If your process is literally 'tail -f', having an extra UNIX process 
around for it is kinda wasteful.  You can get the same effect by 
keeping an open file around and reading the remainder of it every 
second.  (using reactor.callLater)





More information about the Twisted-Python mailing list