aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/asyncio/events.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committerDaniil Cherednik <dcherednik@ydb.tech>2024-02-14 14:26:16 +0000
commit31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch)
treec1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Lib/asyncio/events.py
parentfe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff)
downloadydb-31f2a419764a8ba77c2a970cfc80056c6cd06756.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/asyncio/events.py')
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/events.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/contrib/tools/python3/src/Lib/asyncio/events.py b/contrib/tools/python3/src/Lib/asyncio/events.py
index cfc62156e4..016852880c 100644
--- a/contrib/tools/python3/src/Lib/asyncio/events.py
+++ b/contrib/tools/python3/src/Lib/asyncio/events.py
@@ -17,6 +17,7 @@ __all__ = (
import contextvars
import os
+import signal
import socket
import subprocess
import sys
@@ -65,6 +66,9 @@ class Handle:
info = self._repr_info()
return '<{}>'.format(' '.join(info))
+ def get_context(self):
+ return self._context
+
def cancel(self):
if not self._cancelled:
self._cancelled = True
@@ -675,6 +679,23 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
if (self._local._loop is None and
not self._local._set_called and
threading.current_thread() is threading.main_thread()):
+ stacklevel = 2
+ try:
+ f = sys._getframe(1)
+ except AttributeError:
+ pass
+ else:
+ # Move up the call stack so that the warning is attached
+ # to the line outside asyncio itself.
+ while f:
+ module = f.f_globals.get('__name__')
+ if not (module == 'asyncio' or module.startswith('asyncio.')):
+ break
+ f = f.f_back
+ stacklevel += 1
+ import warnings
+ warnings.warn('There is no current event loop',
+ DeprecationWarning, stacklevel=stacklevel)
self.set_event_loop(self.new_event_loop())
if self._local._loop is None:
@@ -786,14 +807,6 @@ def get_event_loop():
the result of `get_event_loop_policy().get_event_loop()` call.
"""
# NOTE: this function is implemented in C (see _asynciomodule.c)
- return _py__get_event_loop()
-
-
-def _get_event_loop(stacklevel=3):
- # This internal method is going away in Python 3.12, left here only for
- # backwards compatibility with 3.10.0 - 3.10.8 and 3.11.0.
- # Similarly, this method's C equivalent in _asyncio is going away as well.
- # See GH-99949 for more details.
current_loop = _get_running_loop()
if current_loop is not None:
return current_loop
@@ -826,7 +839,6 @@ _py__get_running_loop = _get_running_loop
_py__set_running_loop = _set_running_loop
_py_get_running_loop = get_running_loop
_py_get_event_loop = get_event_loop
-_py__get_event_loop = _get_event_loop
try:
@@ -834,7 +846,7 @@ try:
# functions in asyncio. Pure Python implementation is
# about 4 times slower than C-accelerated.
from _asyncio import (_get_running_loop, _set_running_loop,
- get_running_loop, get_event_loop, _get_event_loop)
+ get_running_loop, get_event_loop)
except ImportError:
pass
else:
@@ -843,4 +855,14 @@ else:
_c__set_running_loop = _set_running_loop
_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()
+ _set_running_loop(None)
+ signal.set_wakeup_fd(-1)
+
+ os.register_at_fork(after_in_child=on_fork)