[Twisted-Python] Named Pipes
Wari Wahab
wari at home.wari.org
Fri May 16 22:45:45 MDT 2003
Moshe Zadka wrote:
>>Hi, is there a way to get twisted to listen to a named pipe like it's a
>>TCP connection or something? How would I go about it?
> It's fairly easy, and probably should be done in Twisted at some point.
Ah, I got my own based on stdio.StandardIO and that does not work the
way I want, this way seems better :)
> from twisted.internet import abstract, fdesc
> class SelectableFile(abstract.FileDescriptor):
> def __init__(self, fp, protocol):
> self.fp = fp
> fdesc.setNonBlocking(fp)
> self.protocol = protocol
> self.protocol.makeConnection(self)
> self.fileno = self.fp.fileno
> def doRead(self):
> buf = self.fp.read(4096)
I had to do this on a try block:
try:
buf = self.fp.read(4096)
except IOError:
buf = None
> if buf:
> self.protocol.dataReceived(buf)
> else:
> self.protocol.connectionLost()
> def write(self, data):
> pass # what can we do with the data?
> def loseConnection(self):
> self.fp.close()
Wait, how did you guys make it so easy? :) Anyway, I find that
loseConnection is never called (when I restart syslog, or when I deleted
the named pipe), this thing goes on like a battery, of course the effect
of deleting the file and recreating it does not get the communications
working anymore because of inode/filepointer diffences.
Thanks for pointing this one out to me.
--
Regards: Wari Wahab
RoughingIT - http://roughingit.subtlehints.net
PyBlosxom - http://roughingit.subtlehints.net/pyblosxom
More information about the Twisted-Python
mailing list