Hi:<br><br>Aren't you adding two readers? One is added in the __init__ method of inputFile, the other in the test code.<br><br>I'm also a newbie so maybe I'm equally confused...<br><br><div class="gmail_quote">
On Tue, Feb 9, 2010 at 8:47 PM, K. Richard Pixley <span dir="ltr"><<a href="mailto:rich@noir.com">rich@noir.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
I'm confused be the response I get to the attached program.<br>
<br>
In a nutshell, I'm building a reader, attaching it with addReader,
later removing it with removeReader. And I'm getting this:<br>
<blockquote><tt>time python test_reactor.py</tt><br>
<tt>Traceback (most recent call last):</tt><br>
<tt>Failure: twisted.internet.error.ConnectionFdescWentAway: Uh:
Filedescriptor went away.</tt><br>
</blockquote>
Which seems to be telling me that I don't know as much yet as I'd hoped.<br>
<br>
Why would the reactor care about a closed file descriptor that isn't
even in it's interest set?<br>
<br>
--rich<br>
</div>
<br>#!/usr/bin/env python<br>
# -*- coding: utf-8 -*-<br>
<br>
import os<br>
<br>
from zope.interface import implements<br>
from twisted.internet import reactor<br>
from twisted.internet.interfaces import IReadDescriptor<br>
<br>
class inputFile(object):<br>
implements(IReadDescriptor)<br>
<br>
def __init__(self, filename):<br>
self.filename = filename<br>
self.filedes = os.open(filename, os.O_RDONLY | os.O_NONBLOCK)<br>
reactor.addReader(self)<br>
<br>
def fileno(self):<br>
return self.filedes<br>
<br>
def connectionLost(self, reason):<br>
raise reason<br>
<br>
def logPrefix(self):<br>
return 'inputFile'<br>
<br>
def doRead(self):<br>
reactor.removeReader(self)<br>
os.close(self.filedes)<br>
self.filedes = -1<br>
reactor.stop()<br>
<br>
if __name__ == '__main__':<br>
r = inputFile('/etc/group')<br>
reactor.addReader(r)<br>
reactor.run()<br>
<br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br>