Author yselivanov
Recipients gvanrossum, vstinner, yselivanov
Date 2014-09-15.01:28:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410744503.92.0.190224565519.issue21998@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2014-09-15 01:28:23yselivanovsetrecipients: + yselivanov, gvanrossum, vstinner
2014-09-15 01:28:23yselivanovsetmessageid: <1410744503.92.0.190224565519.issue21998@psf.upfronthosting.co.za>
2014-09-15 01:28:23yselivanovlinkissue21998 messages
2014-09-15 01:28:23yselivanovcreate