Yury Selivanov added the comment:

> Is there a use case for sharing an event loop across forking?

I don't think so.  I use forking mainly for the following two use-cases:

- Socket sharing for web servers. Solution: if you want to have a shared 
sockets between multiple child processes, just open them in master process, 
fork as many times as you want, and start event 
loops in child processes only.

- If sometimes you want to spawn some child process "on demand". Solution: fork 
before having a loop running, and use the child process as a "template", i.e. 
when you need a new child process - just ask the first child to fork it.

It would certainly be handy to have an ability to fork while the loop is 
running and safely close (and reopen) it in the forked child process. But now I 
can see that it's a non-trivial thing to do properly. Probably it's ~somewhat~ 
safe to re-initialize epoll (or whatever selector we use), re-open self-pipe 
etc, drop all queued callbacks and clear Task.all_tasks collection, but even 
then it's easy to miss something.

I think we just need to make sure that we have documented that asyncio loops 
are not fork safe, and forks in running loops should be avoided by all means.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21998>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to