[docs] [issue19876] selectors (and asyncio?): document behaviour on closed files/sockets

Guido van Rossum report at bugs.python.org
Tue Dec 3 23:45:32 CET 2013

Guido van Rossum added the comment:

Heh, I'd forgotten the behavior of unregister().  It seems that there are two layers to the behavior -- if this FD was never register()ed it will raise; if it was register()ed but has since been close()d it may raise.

For the higher-level APIs in asyncio I chose not to raise from the remove_{reader,writer}() methods -- they return True if something was removed, False if not.  This currently has to be implemented by explicitly asking the selector for the key first.  I.e.:

    def remove_reader(self, fd):
        """Remove a reader callback."""
            key = self._selector.get_key(fd)
        except KeyError:
            return False
            mask, (reader, writer) = key.events, key.data
            mask &= ~selectors.EVENT_READ
            if not mask:
                self._selector.modify(fd, mask, (None, writer))

            if reader is not None:
                return True
                return False


Python tracker <report at bugs.python.org>

More information about the docs mailing list