Hi Rich:<br><br>Try removing the &quot;reactor.addReader(self)&quot; call from &quot;__init__&quot; and see what happens.  That call is made when &quot;r&quot; is created in<br>
<br>
   r = inputFile(&#39;/etc/group&#39;)<br>
<br>
and immediately after that you are calling<br>
   reactor.addReader(r)<br><br>So, you are calling reactor.addReader() twice on the same instance.<br>
<br>
Mark<br><br><div class="gmail_quote">On Wed, Feb 10, 2010 at 2:24 PM, K. Richard Pixley <span dir="ltr">&lt;<a 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 don&#39;t think so.  I believe the reactor is actually added during the
import.  (I learned this as I discovered that reactors can&#39;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&#39;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&#39;s a mistake.  (Or at least, I&#39;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&#39;m thinking that either...<br>
<br>
a) there&#39;s some other way to close out my object that I just haven&#39;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&#39;m just leaving the file descriptor.  But
I&#39;d like to know how this is intended to be used.<br>
<br>
--rich (still a newbie)<br>
<br>
Mark Bailey wrote:
<blockquote type="cite"><div><div></div><div class="h5">Hi:<br>
  <br>
Aren&#39;t you adding two readers?  One is added in the __init__ method of
inputFile, the other in the test code.<br>
  <br>
I&#39;m also a newbie so maybe I&#39;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 href="mailto:rich@noir.com" target="_blank">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&#39;m confused be the response
I get to the attached program.<br>
    <br>
In a nutshell, I&#39;m building a reader, attaching it with addReader,
later removing it with removeReader.  And I&#39;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&#39;t know as much yet as I&#39;d hoped.<br>
    <br>
Why would the reactor care about a closed file descriptor that isn&#39;t
even in it&#39;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 &#39;inputFile&#39;<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__ == &#39;__main__&#39;:<br>
   r = inputFile(&#39;/etc/group&#39;)<br>
   reactor.addReader(r)<br>
   reactor.run()<br>
    <br>
_______________________________________________<br>
Twisted-Python mailing list<br>
    <a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">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>
  </div></div><pre><hr size="4" width="90%"><div class="im">
_______________________________________________
Twisted-Python mailing list
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a>
  </div></pre>
</blockquote>
</div>

<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>