<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I don't think so.&nbsp; I believe the reactor is actually added during the
import.&nbsp; (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.)<br>
<br>
I looked through the code and there's a call in the reactor to fileno
immediately after the call to doRead.&nbsp; It seems to be attempting to
check for file descriptors which broke during the read, but I think
that's a mistake.&nbsp; (Or at least, I'm confused about how else to do
it).&nbsp; Seems to me that the only time my object has control in order to
remove itself is during doRead.&nbsp; So I'm thinking that either...<br>
<br>
a) there's some other way to close out my object that I just haven't
discovered or<br>
<br>
b) the code which checks the file descriptor, (which may have been
closed), after doRead is doing so mistakenly.<br>
<br>
For now, in my real code, I'm just leaving the file descriptor.&nbsp; But
I'd like to know how this is intended to be used.<br>
<br>
--rich (still a newbie)<br>
<br>
Mark Bailey wrote:
<blockquote
 cite="mid:dc408fe51002101057k6d4159e6o132500fe8628d790@mail.gmail.com"
 type="cite">Hi:<br>
  <br>
Aren't you adding two readers?&nbsp; 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">&lt;<a moz-do-not-send="true"
 href="mailto:rich@noir.com">rich@noir.com</a>&gt;</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.&nbsp; And I'm getting this:<br>
    <blockquote>time python test_reactor.py<br>
Traceback (most recent call last):<br>
Failure: twisted.internet.error.ConnectionFdescWentAway: Uh:
Filedescriptor went away.<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>
&nbsp; &nbsp;implements(IReadDescriptor)<br>
    <br>
&nbsp; &nbsp;def __init__(self, filename):<br>
&nbsp; &nbsp; &nbsp; &nbsp;self.filename = filename<br>
&nbsp; &nbsp; &nbsp; &nbsp;self.filedes = os.open(filename, os.O_RDONLY | os.O_NONBLOCK)<br>
&nbsp; &nbsp; &nbsp; &nbsp;reactor.addReader(self)<br>
    <br>
&nbsp; &nbsp;def fileno(self):<br>
&nbsp; &nbsp; &nbsp; &nbsp;return self.filedes<br>
    <br>
&nbsp; &nbsp;def connectionLost(self, reason):<br>
&nbsp; &nbsp; &nbsp; &nbsp;raise reason<br>
    <br>
&nbsp; &nbsp;def logPrefix(self):<br>
&nbsp; &nbsp; &nbsp; &nbsp;return 'inputFile'<br>
    <br>
&nbsp; &nbsp;def doRead(self):<br>
&nbsp; &nbsp; &nbsp; &nbsp;reactor.removeReader(self)<br>
&nbsp; &nbsp; &nbsp; &nbsp;os.close(self.filedes)<br>
&nbsp; &nbsp; &nbsp; &nbsp;self.filedes = -1<br>
&nbsp; &nbsp; &nbsp; &nbsp;reactor.stop()<br>
    <br>
if __name__ == '__main__':<br>
&nbsp; &nbsp;r = inputFile('/etc/group')<br>
&nbsp; &nbsp;reactor.addReader(r)<br>
&nbsp; &nbsp;reactor.run()<br>
    <br>
_______________________________________________<br>
Twisted-Python mailing list<br>
    <a moz-do-not-send="true"
 href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
    <a moz-do-not-send="true"
 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>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Twisted-Python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a>
<a class="moz-txt-link-freetext" href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a>
  </pre>
</blockquote>
</body>
</html>