[Twisted-Python] error in pollreactor.py
![](https://secure.gravatar.com/avatar/86cf6b90f598b8eef7d30d17c0e2c9af.jpg?s=120&d=mm&r=g)
Method _dictRemove of pollreactor.py: def _dictRemove(self, selectable, mdict): try: # the easy way fd = reader.fileno() except: # the hard way: necessary because fileno() may disappear at any # moment, thanks to python's underlying sockets impl for fd, fdes in selectables.items(): if selectable is fdes: break else: # Hmm, maybe not the right course of action? This method can't # fail, because it happens inside error detection... return if mdict.has_key(fd): del mdict[fd] self._updateRegistration(fd) First, "reader.fileno()" is just not going to work because there is no variable "reader" in the scope. This error is hidden by the all-encompassing except clause. Second, this comment about fileno() disappearing... I don't believe it. Does anyone know if this is really true? Code works (in my limited tests) if changed to: def _dictRemove(self, selectable, mdict): fd = selectable.fileno() if mdict.has_key(fd): del mdict[fd] self._updateRegistration(fd) -Eric
![](https://secure.gravatar.com/avatar/56e4cc78ea7fcf3bb37888ebf23bc1f0.jpg?s=120&d=mm&r=g)
On Sun, Aug 31, 2003 at 04:48:47PM -0400, Eric C. Newton wrote:
Method _dictRemove of pollreactor.py:
def _dictRemove(self, selectable, mdict): try: # the easy way fd = reader.fileno() except: # the hard way: necessary because fileno() may disappear at any # moment, thanks to python's underlying sockets impl for fd, fdes in selectables.items(): if selectable is fdes: break else: # Hmm, maybe not the right course of action? This method can't # fail, because it happens inside error detection... return if mdict.has_key(fd): del mdict[fd] self._updateRegistration(fd)
First, "reader.fileno()" is just not going to work because there is no variable "reader" in the scope. This error is hidden by the all-encompassing except clause. Second, this comment about fileno() disappearing... I don't believe it. Does anyone know if this is really true?
What the comment really means, I believe, is that fileno() may return -1 at any time, without warning. -1 will never be in the dict, so a lookup for what the file descriptor used to be must be done.
Code works (in my limited tests) if changed to:
def _dictRemove(self, selectable, mdict): fd = selectable.fileno() if mdict.has_key(fd): del mdict[fd] self._updateRegistration(fd)
I think you're on the right track, but would use this instead: def _dictRemove(self, selectable, mdict): fd = selectable.fileno() if fd == -1: for fd, fdes in selectables.iteritems(): if fdes is selectable: break else: # This should probably be reported. It should # never happen. return try: del mdict[fd] except KeyError: pass else: self._updateRegistration(fd) Jp -- http://catandgirl.com/view.cgi?44
participants (2)
-
Eric C. Newton
-
Jp Calderone