<!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">
Doh. You're right about the double registration. Thanks. But that
doesn't change my problem.<br>
<br>
The reactor still complains about the busted descriptor after removing
the reader and reseting my descriptor to -1.<br>
<br>
--rich<br>
<br>
Mark Bailey wrote:
<blockquote
cite="mid:dc408fe51002101144h6558578dtddcf6f724cfa2e32@mail.gmail.com"
type="cite">Hi Rich:<br>
<br>
Try removing the "reactor.addReader(self)" call from "__init__" and see
what happens. That call is made when "r" is created in<br>
<br>
r = inputFile('/etc/group')<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"><<a moz-do-not-send="true"
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 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.)<br>
<br>
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...<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. 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 type="cite">
<div>
<div class="h5">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 moz-do-not-send="true"
href="mailto:rich@noir.com" target="_blank">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>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>
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 moz-do-not-send="true"
href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">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>
</div>
</div>
<pre><hr size="4" width="90%"><div class="im">
_______________________________________________
Twisted-Python mailing list
<a moz-do-not-send="true" href="mailto:Twisted-Python@twistedmatrix.com"
target="_blank">Twisted-Python@twistedmatrix.com</a>
<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>
</div></pre>
</blockquote>
</div>
<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>