summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-11-27 05:54:48 (GMT)
committerGitHub <noreply@github.com>2022-11-27 05:54:48 (GMT)
commit191708c56cf45e0e1c98a0e7292ffa67b7e3b09c (patch)
treec9437bfc79d3da169c2907d36cf151e6e5a619cd /Lib/asyncio
parent024ac542d738f56b36bdeb3517a10e93da5acab9 (diff)
downloadcpython-191708c56cf45e0e1c98a0e7292ffa67b7e3b09c.zip
cpython-191708c56cf45e0e1c98a0e7292ffa67b7e3b09c.tar.gz
cpython-191708c56cf45e0e1c98a0e7292ffa67b7e3b09c.tar.bz2
GH-66285: fix forking in asyncio (#99769)
Closes #66285
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/events.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index a327ba5..2836bbc 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -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)