Hi:
Aren't you adding two readers? One is added in the __init__ method of inputFile, the other in the test code.
I'm also a newbie so maybe I'm equally confused...
On Tue, Feb 9, 2010 at 8:47 PM, K. Richard Pixley <rich@noir.com> wrote:
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.pyWhich seems to be telling me that I don't know as much yet as I'd hoped.
Traceback (most recent call last):
Failure: twisted.internet.error.ConnectionFdescWentAway: Uh: Filedescriptor went away.
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
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python