aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-11-24 09:10:27 +0530
committerGitHub <noreply@github.com>2022-11-24 09:10:27 +0530
commit0c1fbc17b48f56c6070d335ed291a24c91ed190a (patch)
treefd255e556f7245eaa7878483f2747681cbaabb83 /Lib/asyncio
parent9dc08361bef67a331d1609c8629314c0ca5a79d5 (diff)
downloadcpython-0c1fbc17b48f56c6070d335ed291a24c91ed190a.tar.gz
cpython-0c1fbc17b48f56c6070d335ed291a24c91ed190a.zip
GH-66285: fix forking in `asyncio` (#99539)
`asyncio` now does not shares event loop and signal wakeupfd in forked processes.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/events.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index a327ba54a32..39a01048b4c 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -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.