[Twisted-Python] How does the pollreactor work?
rlott at evertz.com
Fri Aug 29 11:35:59 EDT 2008
I have been trying to figure out how to use the twisted.internet.pollreactor so that I can use it to monitor a Linux named PIPE (i.e. a FIFO created using mkfifo()). I tried without success to Google some examples but I couldn't find anything.
Now, for a simple TCP server, the setup looks something like this (i.e. like the QOTD example in the documentation):
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
self.transport.write("An apple a day keeps the doctor away\r\n")
# Next lines are magic:
factory = Factory()
factory.protocol = QOTD
# 8007 is the port you want to run under. Choose something >1024
So, the TCP type of reactor has something that tells it to listen to port 8007 and use some form of factory or object to take care of things when a connection occurs. As far as I can guess, I would need to do some steps like this (NOTE: using mixture of real and pseudo code):
from twisted.internet import pollreactor
<create a FileDescriptor object using /tmp/myfifo, maybe a class?>
<use the reactor.addReader() call to register the FileDescriptor object with the reactor>
<call reactor.run() (no loop) or call reactor.doPoll() (in a loop, processing returned events)?>
Anyways, if anyone can give me some direction on how this reactor works. Ideally, I would assume that the relationships would be somewhat like this:
Protocol analogous to FileDescriptor
reactor.listenTCP analogous to reactor.addReader()
reactor.run() would invoke the appropriate call in my FileDescriptor-based class to handle any read events on /tmp/myfifo
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python