[Twisted-Python] error in pollreactor.py

Eric C. Newton ecn at metaslash.com
Sun Aug 31 14:48:47 MDT 2003


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




More information about the Twisted-Python mailing list