I'm confused be the response I get to the attached program.

In a nutshell, I'm building a reader, attaching it with addReader, later removing it with removeReader. And I'm getting this:

   time python test_reactor.py
   Traceback (most recent call last):
   Failure: twisted.internet.error.ConnectionFdescWentAway: Uh:
   Filedescriptor went away.

Which seems to be telling me that I don't know as much yet as I'd hoped.

Why would the reactor care about a closed file descriptor that isn't even in it's interest set?

--rich
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from zope.interface import implements
from twisted.internet import reactor
from twisted.internet.interfaces import IReadDescriptor

class inputFile(object):
    implements(IReadDescriptor)

    def __init__(self, filename):
        self.filename = filename
        self.filedes = os.open(filename, os.O_RDONLY | os.O_NONBLOCK)
        reactor.addReader(self)

    def fileno(self):
        return self.filedes

    def connectionLost(self, reason):
        raise reason

    def logPrefix(self):
        return 'inputFile'

    def doRead(self):
        reactor.removeReader(self)
        os.close(self.filedes)
        self.filedes = -1
        reactor.stop()

if __name__ == '__main__':
    r = inputFile('/etc/group')
    reactor.addReader(r)
    reactor.run()
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to