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

Closes #66285
This commit is contained in:
Kumar Aditya 2022-11-27 11:24:48 +05:30 committed by GitHub
parent 024ac542d7
commit 191708c56c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 0 deletions

View file

@ -13,6 +13,7 @@ __all__ = (
import contextvars
import os
import signal
import socket
import subprocess
import sys
@ -842,3 +843,13 @@ else:
_c_get_running_loop = get_running_loop
_c_get_event_loop = get_event_loop
_c__get_event_loop = _get_event_loop
if hasattr(os, 'fork'):
def on_fork():
# Reset the loop and wakeupfd in the forked child process.
if _event_loop_policy is not None:
_event_loop_policy._local = BaseDefaultEventLoopPolicy._Local()
signal.set_wakeup_fd(-1)
os.register_at_fork(after_in_child=on_fork)