I don't think so. I believe the reactor is actually added during the
import. (I learned this as I discovered that reactors can't be
restarted, which means you have to manually create a new one as a
fixture for simple unittest work.)
I looked through the code and there's a call in the reactor to fileno
immediately after the call to doRead. It seems to be attempting to
check for file descriptors which broke during the read, but I think
that's a mistake. (Or at least, I'm confused about how else to do it).
Seems to me that the only time my object has control in order to remove
itself is during doRead. So I'm thinking that either...
a) there's some other way to close out my object that I just haven't
discovered or
b) the code which checks the file descriptor, (which may have been
closed), after doRead is doing so mistakenly.
For now, in my real code, I'm just leaving the file descriptor. But I'd
like to know how this is intended to be used.
--rich (still a newbie)
Mark Bailey wrote:
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 <[email protected]
<mailto:[email protected]>> 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.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
[email protected]
<mailto:[email protected]>
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
------------------------------------------------------------------------
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python