[issue21998] asyncio: support fork

STINNER Victor report at bugs.python.org
Tue Feb 17 22:27:13 CET 2015


STINNER Victor added the comment:

2015-02-17 20:16 GMT+01:00 Charles-François Natali <report at bugs.python.org>:
> What would you do with the selector after fork(): register the FDs in
> a new epoll, remove them?

See the patch:

+        def _at_fork(self):
+            # don't unregister file descriptors: epoll is still shared with
+            # the parent process
+            self._epoll = select.epoll()
+            for key in self._fd_to_key.values():
+                self._register(key)

EpollSelector._at_fork() does nothing on the current epoll object,
create a new epoll object and register again all file descriptor.

Hum, I should maybe close explicitly the old epoll object.

> There's no sensible default behavior, and I'd rrather avoid polluting
> the code for this.

What is wrong with the proposed patch?

> If asyncio wants to support this, it can create a new selector and
> re-register everything it wants manually: there's a Selector.get_map()
> exposing all that's needed.

If possible, I would prefer to implement "at fork" in the selectors
module directly, the selectors module has a better knowledge of
seletors. For example, asyncio is not aware of the selector._epoll
attribute.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21998>
_______________________________________


More information about the Python-bugs-list mailing list