GH-66285: fix forking in asyncio (#99539)

`asyncio` now does not shares event loop and signal wakeupfd in forked processes.
This commit is contained in:
Kumar Aditya 2022-11-24 09:10:27 +05:30 committed by GitHub
parent 9dc08361be
commit 0c1fbc17b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 0 deletions

View file

@ -17,6 +17,7 @@ import socket
import subprocess
import sys
import threading
import signal
from . import format_helpers
@ -665,6 +666,14 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
def __init__(self):
self._local = self._Local()
if hasattr(os, 'fork'):
def on_fork():
# Reset the loop and wakeupfd in the forked child process.
self._local = self._Local()
signal.set_wakeup_fd(-1)
os.register_at_fork(after_in_child=on_fork)
def get_event_loop(self):
"""Get the event loop for the current context.