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."""
try:
key = self._selector.get_key(fd)
except KeyError:
return False
else:
mask, (reader, writer) = key.events, key.data
mask &= ~selectors.EVENT_READ
if not mask:
self._selector.unregister(fd)
else:
self._selector.modify(fd, mask, (None, writer))
if reader is not None:
reader.cancel()
return True
else:
return False
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19876>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com