logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

events.py (27151B)


  1. """Event loop and event loop policy."""
  2. __all__ = (
  3. 'AbstractEventLoopPolicy',
  4. 'AbstractEventLoop', 'AbstractServer',
  5. 'Handle', 'TimerHandle',
  6. 'get_event_loop_policy', 'set_event_loop_policy',
  7. 'get_event_loop', 'set_event_loop', 'new_event_loop',
  8. 'get_child_watcher', 'set_child_watcher',
  9. '_set_running_loop', 'get_running_loop',
  10. '_get_running_loop',
  11. )
  12. import contextvars
  13. import os
  14. import socket
  15. import subprocess
  16. import sys
  17. import threading
  18. from . import format_helpers
  19. class Handle:
  20. """Object returned by callback registration methods."""
  21. __slots__ = ('_callback', '_args', '_cancelled', '_loop',
  22. '_source_traceback', '_repr', '__weakref__',
  23. '_context')
  24. def __init__(self, callback, args, loop, context=None):
  25. if context is None:
  26. context = contextvars.copy_context()
  27. self._context = context
  28. self._loop = loop
  29. self._callback = callback
  30. self._args = args
  31. self._cancelled = False
  32. self._repr = None
  33. if self._loop.get_debug():
  34. self._source_traceback = format_helpers.extract_stack(
  35. sys._getframe(1))
  36. else:
  37. self._source_traceback = None
  38. def _repr_info(self):
  39. info = [self.__class__.__name__]
  40. if self._cancelled:
  41. info.append('cancelled')
  42. if self._callback is not None:
  43. info.append(format_helpers._format_callback_source(
  44. self._callback, self._args))
  45. if self._source_traceback:
  46. frame = self._source_traceback[-1]
  47. info.append(f'created at {frame[0]}:{frame[1]}')
  48. return info
  49. def __repr__(self):
  50. if self._repr is not None:
  51. return self._repr
  52. info = self._repr_info()
  53. return '<{}>'.format(' '.join(info))
  54. def cancel(self):
  55. if not self._cancelled:
  56. self._cancelled = True
  57. if self._loop.get_debug():
  58. # Keep a representation in debug mode to keep callback and
  59. # parameters. For example, to log the warning
  60. # "Executing <Handle...> took 2.5 second"
  61. self._repr = repr(self)
  62. self._callback = None
  63. self._args = None
  64. def cancelled(self):
  65. return self._cancelled
  66. def _run(self):
  67. try:
  68. self._context.run(self._callback, *self._args)
  69. except (SystemExit, KeyboardInterrupt):
  70. raise
  71. except BaseException as exc:
  72. cb = format_helpers._format_callback_source(
  73. self._callback, self._args)
  74. msg = f'Exception in callback {cb}'
  75. context = {
  76. 'message': msg,
  77. 'exception': exc,
  78. 'handle': self,
  79. }
  80. if self._source_traceback:
  81. context['source_traceback'] = self._source_traceback
  82. self._loop.call_exception_handler(context)
  83. self = None # Needed to break cycles when an exception occurs.
  84. class TimerHandle(Handle):
  85. """Object returned by timed callback registration methods."""
  86. __slots__ = ['_scheduled', '_when']
  87. def __init__(self, when, callback, args, loop, context=None):
  88. assert when is not None
  89. super().__init__(callback, args, loop, context)
  90. if self._source_traceback:
  91. del self._source_traceback[-1]
  92. self._when = when
  93. self._scheduled = False
  94. def _repr_info(self):
  95. info = super()._repr_info()
  96. pos = 2 if self._cancelled else 1
  97. info.insert(pos, f'when={self._when}')
  98. return info
  99. def __hash__(self):
  100. return hash(self._when)
  101. def __lt__(self, other):
  102. if isinstance(other, TimerHandle):
  103. return self._when < other._when
  104. return NotImplemented
  105. def __le__(self, other):
  106. if isinstance(other, TimerHandle):
  107. return self._when < other._when or self.__eq__(other)
  108. return NotImplemented
  109. def __gt__(self, other):
  110. if isinstance(other, TimerHandle):
  111. return self._when > other._when
  112. return NotImplemented
  113. def __ge__(self, other):
  114. if isinstance(other, TimerHandle):
  115. return self._when > other._when or self.__eq__(other)
  116. return NotImplemented
  117. def __eq__(self, other):
  118. if isinstance(other, TimerHandle):
  119. return (self._when == other._when and
  120. self._callback == other._callback and
  121. self._args == other._args and
  122. self._cancelled == other._cancelled)
  123. return NotImplemented
  124. def cancel(self):
  125. if not self._cancelled:
  126. self._loop._timer_handle_cancelled(self)
  127. super().cancel()
  128. def when(self):
  129. """Return a scheduled callback time.
  130. The time is an absolute timestamp, using the same time
  131. reference as loop.time().
  132. """
  133. return self._when
  134. class AbstractServer:
  135. """Abstract server returned by create_server()."""
  136. def close(self):
  137. """Stop serving. This leaves existing connections open."""
  138. raise NotImplementedError
  139. def get_loop(self):
  140. """Get the event loop the Server object is attached to."""
  141. raise NotImplementedError
  142. def is_serving(self):
  143. """Return True if the server is accepting connections."""
  144. raise NotImplementedError
  145. async def start_serving(self):
  146. """Start accepting connections.
  147. This method is idempotent, so it can be called when
  148. the server is already being serving.
  149. """
  150. raise NotImplementedError
  151. async def serve_forever(self):
  152. """Start accepting connections until the coroutine is cancelled.
  153. The server is closed when the coroutine is cancelled.
  154. """
  155. raise NotImplementedError
  156. async def wait_closed(self):
  157. """Coroutine to wait until service is closed."""
  158. raise NotImplementedError
  159. async def __aenter__(self):
  160. return self
  161. async def __aexit__(self, *exc):
  162. self.close()
  163. await self.wait_closed()
  164. class AbstractEventLoop:
  165. """Abstract event loop."""
  166. # Running and stopping the event loop.
  167. def run_forever(self):
  168. """Run the event loop until stop() is called."""
  169. raise NotImplementedError
  170. def run_until_complete(self, future):
  171. """Run the event loop until a Future is done.
  172. Return the Future's result, or raise its exception.
  173. """
  174. raise NotImplementedError
  175. def stop(self):
  176. """Stop the event loop as soon as reasonable.
  177. Exactly how soon that is may depend on the implementation, but
  178. no more I/O callbacks should be scheduled.
  179. """
  180. raise NotImplementedError
  181. def is_running(self):
  182. """Return whether the event loop is currently running."""
  183. raise NotImplementedError
  184. def is_closed(self):
  185. """Returns True if the event loop was closed."""
  186. raise NotImplementedError
  187. def close(self):
  188. """Close the loop.
  189. The loop should not be running.
  190. This is idempotent and irreversible.
  191. No other methods should be called after this one.
  192. """
  193. raise NotImplementedError
  194. async def shutdown_asyncgens(self):
  195. """Shutdown all active asynchronous generators."""
  196. raise NotImplementedError
  197. async def shutdown_default_executor(self):
  198. """Schedule the shutdown of the default executor."""
  199. raise NotImplementedError
  200. # Methods scheduling callbacks. All these return Handles.
  201. def _timer_handle_cancelled(self, handle):
  202. """Notification that a TimerHandle has been cancelled."""
  203. raise NotImplementedError
  204. def call_soon(self, callback, *args):
  205. return self.call_later(0, callback, *args)
  206. def call_later(self, delay, callback, *args):
  207. raise NotImplementedError
  208. def call_at(self, when, callback, *args):
  209. raise NotImplementedError
  210. def time(self):
  211. raise NotImplementedError
  212. def create_future(self):
  213. raise NotImplementedError
  214. # Method scheduling a coroutine object: create a task.
  215. def create_task(self, coro, *, name=None):
  216. raise NotImplementedError
  217. # Methods for interacting with threads.
  218. def call_soon_threadsafe(self, callback, *args):
  219. raise NotImplementedError
  220. def run_in_executor(self, executor, func, *args):
  221. raise NotImplementedError
  222. def set_default_executor(self, executor):
  223. raise NotImplementedError
  224. # Network I/O methods returning Futures.
  225. async def getaddrinfo(self, host, port, *,
  226. family=0, type=0, proto=0, flags=0):
  227. raise NotImplementedError
  228. async def getnameinfo(self, sockaddr, flags=0):
  229. raise NotImplementedError
  230. async def create_connection(
  231. self, protocol_factory, host=None, port=None,
  232. *, ssl=None, family=0, proto=0,
  233. flags=0, sock=None, local_addr=None,
  234. server_hostname=None,
  235. ssl_handshake_timeout=None,
  236. happy_eyeballs_delay=None, interleave=None):
  237. raise NotImplementedError
  238. async def create_server(
  239. self, protocol_factory, host=None, port=None,
  240. *, family=socket.AF_UNSPEC,
  241. flags=socket.AI_PASSIVE, sock=None, backlog=100,
  242. ssl=None, reuse_address=None, reuse_port=None,
  243. ssl_handshake_timeout=None,
  244. start_serving=True):
  245. """A coroutine which creates a TCP server bound to host and port.
  246. The return value is a Server object which can be used to stop
  247. the service.
  248. If host is an empty string or None all interfaces are assumed
  249. and a list of multiple sockets will be returned (most likely
  250. one for IPv4 and another one for IPv6). The host parameter can also be
  251. a sequence (e.g. list) of hosts to bind to.
  252. family can be set to either AF_INET or AF_INET6 to force the
  253. socket to use IPv4 or IPv6. If not set it will be determined
  254. from host (defaults to AF_UNSPEC).
  255. flags is a bitmask for getaddrinfo().
  256. sock can optionally be specified in order to use a preexisting
  257. socket object.
  258. backlog is the maximum number of queued connections passed to
  259. listen() (defaults to 100).
  260. ssl can be set to an SSLContext to enable SSL over the
  261. accepted connections.
  262. reuse_address tells the kernel to reuse a local socket in
  263. TIME_WAIT state, without waiting for its natural timeout to
  264. expire. If not specified will automatically be set to True on
  265. UNIX.
  266. reuse_port tells the kernel to allow this endpoint to be bound to
  267. the same port as other existing endpoints are bound to, so long as
  268. they all set this flag when being created. This option is not
  269. supported on Windows.
  270. ssl_handshake_timeout is the time in seconds that an SSL server
  271. will wait for completion of the SSL handshake before aborting the
  272. connection. Default is 60s.
  273. start_serving set to True (default) causes the created server
  274. to start accepting connections immediately. When set to False,
  275. the user should await Server.start_serving() or Server.serve_forever()
  276. to make the server to start accepting connections.
  277. """
  278. raise NotImplementedError
  279. async def sendfile(self, transport, file, offset=0, count=None,
  280. *, fallback=True):
  281. """Send a file through a transport.
  282. Return an amount of sent bytes.
  283. """
  284. raise NotImplementedError
  285. async def start_tls(self, transport, protocol, sslcontext, *,
  286. server_side=False,
  287. server_hostname=None,
  288. ssl_handshake_timeout=None):
  289. """Upgrade a transport to TLS.
  290. Return a new transport that *protocol* should start using
  291. immediately.
  292. """
  293. raise NotImplementedError
  294. async def create_unix_connection(
  295. self, protocol_factory, path=None, *,
  296. ssl=None, sock=None,
  297. server_hostname=None,
  298. ssl_handshake_timeout=None):
  299. raise NotImplementedError
  300. async def create_unix_server(
  301. self, protocol_factory, path=None, *,
  302. sock=None, backlog=100, ssl=None,
  303. ssl_handshake_timeout=None,
  304. start_serving=True):
  305. """A coroutine which creates a UNIX Domain Socket server.
  306. The return value is a Server object, which can be used to stop
  307. the service.
  308. path is a str, representing a file system path to bind the
  309. server socket to.
  310. sock can optionally be specified in order to use a preexisting
  311. socket object.
  312. backlog is the maximum number of queued connections passed to
  313. listen() (defaults to 100).
  314. ssl can be set to an SSLContext to enable SSL over the
  315. accepted connections.
  316. ssl_handshake_timeout is the time in seconds that an SSL server
  317. will wait for the SSL handshake to complete (defaults to 60s).
  318. start_serving set to True (default) causes the created server
  319. to start accepting connections immediately. When set to False,
  320. the user should await Server.start_serving() or Server.serve_forever()
  321. to make the server to start accepting connections.
  322. """
  323. raise NotImplementedError
  324. async def connect_accepted_socket(
  325. self, protocol_factory, sock,
  326. *, ssl=None,
  327. ssl_handshake_timeout=None):
  328. """Handle an accepted connection.
  329. This is used by servers that accept connections outside of
  330. asyncio, but use asyncio to handle connections.
  331. This method is a coroutine. When completed, the coroutine
  332. returns a (transport, protocol) pair.
  333. """
  334. raise NotImplementedError
  335. async def create_datagram_endpoint(self, protocol_factory,
  336. local_addr=None, remote_addr=None, *,
  337. family=0, proto=0, flags=0,
  338. reuse_address=None, reuse_port=None,
  339. allow_broadcast=None, sock=None):
  340. """A coroutine which creates a datagram endpoint.
  341. This method will try to establish the endpoint in the background.
  342. When successful, the coroutine returns a (transport, protocol) pair.
  343. protocol_factory must be a callable returning a protocol instance.
  344. socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on
  345. host (or family if specified), socket type SOCK_DGRAM.
  346. reuse_address tells the kernel to reuse a local socket in
  347. TIME_WAIT state, without waiting for its natural timeout to
  348. expire. If not specified it will automatically be set to True on
  349. UNIX.
  350. reuse_port tells the kernel to allow this endpoint to be bound to
  351. the same port as other existing endpoints are bound to, so long as
  352. they all set this flag when being created. This option is not
  353. supported on Windows and some UNIX's. If the
  354. :py:data:`~socket.SO_REUSEPORT` constant is not defined then this
  355. capability is unsupported.
  356. allow_broadcast tells the kernel to allow this endpoint to send
  357. messages to the broadcast address.
  358. sock can optionally be specified in order to use a preexisting
  359. socket object.
  360. """
  361. raise NotImplementedError
  362. # Pipes and subprocesses.
  363. async def connect_read_pipe(self, protocol_factory, pipe):
  364. """Register read pipe in event loop. Set the pipe to non-blocking mode.
  365. protocol_factory should instantiate object with Protocol interface.
  366. pipe is a file-like object.
  367. Return pair (transport, protocol), where transport supports the
  368. ReadTransport interface."""
  369. # The reason to accept file-like object instead of just file descriptor
  370. # is: we need to own pipe and close it at transport finishing
  371. # Can got complicated errors if pass f.fileno(),
  372. # close fd in pipe transport then close f and vise versa.
  373. raise NotImplementedError
  374. async def connect_write_pipe(self, protocol_factory, pipe):
  375. """Register write pipe in event loop.
  376. protocol_factory should instantiate object with BaseProtocol interface.
  377. Pipe is file-like object already switched to nonblocking.
  378. Return pair (transport, protocol), where transport support
  379. WriteTransport interface."""
  380. # The reason to accept file-like object instead of just file descriptor
  381. # is: we need to own pipe and close it at transport finishing
  382. # Can got complicated errors if pass f.fileno(),
  383. # close fd in pipe transport then close f and vise versa.
  384. raise NotImplementedError
  385. async def subprocess_shell(self, protocol_factory, cmd, *,
  386. stdin=subprocess.PIPE,
  387. stdout=subprocess.PIPE,
  388. stderr=subprocess.PIPE,
  389. **kwargs):
  390. raise NotImplementedError
  391. async def subprocess_exec(self, protocol_factory, *args,
  392. stdin=subprocess.PIPE,
  393. stdout=subprocess.PIPE,
  394. stderr=subprocess.PIPE,
  395. **kwargs):
  396. raise NotImplementedError
  397. # Ready-based callback registration methods.
  398. # The add_*() methods return None.
  399. # The remove_*() methods return True if something was removed,
  400. # False if there was nothing to delete.
  401. def add_reader(self, fd, callback, *args):
  402. raise NotImplementedError
  403. def remove_reader(self, fd):
  404. raise NotImplementedError
  405. def add_writer(self, fd, callback, *args):
  406. raise NotImplementedError
  407. def remove_writer(self, fd):
  408. raise NotImplementedError
  409. # Completion based I/O methods returning Futures.
  410. async def sock_recv(self, sock, nbytes):
  411. raise NotImplementedError
  412. async def sock_recv_into(self, sock, buf):
  413. raise NotImplementedError
  414. async def sock_sendall(self, sock, data):
  415. raise NotImplementedError
  416. async def sock_connect(self, sock, address):
  417. raise NotImplementedError
  418. async def sock_accept(self, sock):
  419. raise NotImplementedError
  420. async def sock_sendfile(self, sock, file, offset=0, count=None,
  421. *, fallback=None):
  422. raise NotImplementedError
  423. # Signal handling.
  424. def add_signal_handler(self, sig, callback, *args):
  425. raise NotImplementedError
  426. def remove_signal_handler(self, sig):
  427. raise NotImplementedError
  428. # Task factory.
  429. def set_task_factory(self, factory):
  430. raise NotImplementedError
  431. def get_task_factory(self):
  432. raise NotImplementedError
  433. # Error handlers.
  434. def get_exception_handler(self):
  435. raise NotImplementedError
  436. def set_exception_handler(self, handler):
  437. raise NotImplementedError
  438. def default_exception_handler(self, context):
  439. raise NotImplementedError
  440. def call_exception_handler(self, context):
  441. raise NotImplementedError
  442. # Debug flag management.
  443. def get_debug(self):
  444. raise NotImplementedError
  445. def set_debug(self, enabled):
  446. raise NotImplementedError
  447. class AbstractEventLoopPolicy:
  448. """Abstract policy for accessing the event loop."""
  449. def get_event_loop(self):
  450. """Get the event loop for the current context.
  451. Returns an event loop object implementing the BaseEventLoop interface,
  452. or raises an exception in case no event loop has been set for the
  453. current context and the current policy does not specify to create one.
  454. It should never return None."""
  455. raise NotImplementedError
  456. def set_event_loop(self, loop):
  457. """Set the event loop for the current context to loop."""
  458. raise NotImplementedError
  459. def new_event_loop(self):
  460. """Create and return a new event loop object according to this
  461. policy's rules. If there's need to set this loop as the event loop for
  462. the current context, set_event_loop must be called explicitly."""
  463. raise NotImplementedError
  464. # Child processes handling (Unix only).
  465. def get_child_watcher(self):
  466. "Get the watcher for child processes."
  467. raise NotImplementedError
  468. def set_child_watcher(self, watcher):
  469. """Set the watcher for child processes."""
  470. raise NotImplementedError
  471. class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
  472. """Default policy implementation for accessing the event loop.
  473. In this policy, each thread has its own event loop. However, we
  474. only automatically create an event loop by default for the main
  475. thread; other threads by default have no event loop.
  476. Other policies may have different rules (e.g. a single global
  477. event loop, or automatically creating an event loop per thread, or
  478. using some other notion of context to which an event loop is
  479. associated).
  480. """
  481. _loop_factory = None
  482. class _Local(threading.local):
  483. _loop = None
  484. _set_called = False
  485. def __init__(self):
  486. self._local = self._Local()
  487. def get_event_loop(self):
  488. """Get the event loop for the current context.
  489. Returns an instance of EventLoop or raises an exception.
  490. """
  491. if (self._local._loop is None and
  492. not self._local._set_called and
  493. threading.current_thread() is threading.main_thread()):
  494. self.set_event_loop(self.new_event_loop())
  495. if self._local._loop is None:
  496. raise RuntimeError('There is no current event loop in thread %r.'
  497. % threading.current_thread().name)
  498. return self._local._loop
  499. def set_event_loop(self, loop):
  500. """Set the event loop."""
  501. self._local._set_called = True
  502. assert loop is None or isinstance(loop, AbstractEventLoop)
  503. self._local._loop = loop
  504. def new_event_loop(self):
  505. """Create a new event loop.
  506. You must call set_event_loop() to make this the current event
  507. loop.
  508. """
  509. return self._loop_factory()
  510. # Event loop policy. The policy itself is always global, even if the
  511. # policy's rules say that there is an event loop per thread (or other
  512. # notion of context). The default policy is installed by the first
  513. # call to get_event_loop_policy().
  514. _event_loop_policy = None
  515. # Lock for protecting the on-the-fly creation of the event loop policy.
  516. _lock = threading.Lock()
  517. # A TLS for the running event loop, used by _get_running_loop.
  518. class _RunningLoop(threading.local):
  519. loop_pid = (None, None)
  520. _running_loop = _RunningLoop()
  521. def get_running_loop():
  522. """Return the running event loop. Raise a RuntimeError if there is none.
  523. This function is thread-specific.
  524. """
  525. # NOTE: this function is implemented in C (see _asynciomodule.c)
  526. loop = _get_running_loop()
  527. if loop is None:
  528. raise RuntimeError('no running event loop')
  529. return loop
  530. def _get_running_loop():
  531. """Return the running event loop or None.
  532. This is a low-level function intended to be used by event loops.
  533. This function is thread-specific.
  534. """
  535. # NOTE: this function is implemented in C (see _asynciomodule.c)
  536. running_loop, pid = _running_loop.loop_pid
  537. if running_loop is not None and pid == os.getpid():
  538. return running_loop
  539. def _set_running_loop(loop):
  540. """Set the running event loop.
  541. This is a low-level function intended to be used by event loops.
  542. This function is thread-specific.
  543. """
  544. # NOTE: this function is implemented in C (see _asynciomodule.c)
  545. _running_loop.loop_pid = (loop, os.getpid())
  546. def _init_event_loop_policy():
  547. global _event_loop_policy
  548. with _lock:
  549. if _event_loop_policy is None: # pragma: no branch
  550. from . import DefaultEventLoopPolicy
  551. _event_loop_policy = DefaultEventLoopPolicy()
  552. def get_event_loop_policy():
  553. """Get the current event loop policy."""
  554. if _event_loop_policy is None:
  555. _init_event_loop_policy()
  556. return _event_loop_policy
  557. def set_event_loop_policy(policy):
  558. """Set the current event loop policy.
  559. If policy is None, the default policy is restored."""
  560. global _event_loop_policy
  561. assert policy is None or isinstance(policy, AbstractEventLoopPolicy)
  562. _event_loop_policy = policy
  563. def get_event_loop():
  564. """Return an asyncio event loop.
  565. When called from a coroutine or a callback (e.g. scheduled with call_soon
  566. or similar API), this function will always return the running event loop.
  567. If there is no running event loop set, the function will return
  568. the result of `get_event_loop_policy().get_event_loop()` call.
  569. """
  570. # NOTE: this function is implemented in C (see _asynciomodule.c)
  571. return _py__get_event_loop()
  572. def _get_event_loop(stacklevel=3):
  573. current_loop = _get_running_loop()
  574. if current_loop is not None:
  575. return current_loop
  576. import warnings
  577. warnings.warn('There is no current event loop',
  578. DeprecationWarning, stacklevel=stacklevel)
  579. return get_event_loop_policy().get_event_loop()
  580. def set_event_loop(loop):
  581. """Equivalent to calling get_event_loop_policy().set_event_loop(loop)."""
  582. get_event_loop_policy().set_event_loop(loop)
  583. def new_event_loop():
  584. """Equivalent to calling get_event_loop_policy().new_event_loop()."""
  585. return get_event_loop_policy().new_event_loop()
  586. def get_child_watcher():
  587. """Equivalent to calling get_event_loop_policy().get_child_watcher()."""
  588. return get_event_loop_policy().get_child_watcher()
  589. def set_child_watcher(watcher):
  590. """Equivalent to calling
  591. get_event_loop_policy().set_child_watcher(watcher)."""
  592. return get_event_loop_policy().set_child_watcher(watcher)
  593. # Alias pure-Python implementations for testing purposes.
  594. _py__get_running_loop = _get_running_loop
  595. _py__set_running_loop = _set_running_loop
  596. _py_get_running_loop = get_running_loop
  597. _py_get_event_loop = get_event_loop
  598. _py__get_event_loop = _get_event_loop
  599. try:
  600. # get_event_loop() is one of the most frequently called
  601. # functions in asyncio. Pure Python implementation is
  602. # about 4 times slower than C-accelerated.
  603. from _asyncio import (_get_running_loop, _set_running_loop,
  604. get_running_loop, get_event_loop, _get_event_loop)
  605. except ImportError:
  606. pass
  607. else:
  608. # Alias C implementations for testing purposes.
  609. _c__get_running_loop = _get_running_loop
  610. _c__set_running_loop = _set_running_loop
  611. _c_get_running_loop = get_running_loop
  612. _c_get_event_loop = get_event_loop
  613. _c__get_event_loop = _get_event_loop