| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from collections.abc import AsyncIterator |
| 4 |
from contextlib import AbstractContextManager |
| 5 |
from signal import Signals |
| 6 |
|
| 7 |
from ._eventloop import get_async_backend |
| 8 |
|
| 9 |
|
| 10 |
def open_signal_receiver( |
| 11 |
*signals: Signals, |
| 12 |
) -> AbstractContextManager[AsyncIterator[Signals]]: |
| 13 |
""" |
| 14 |
Start receiving operating system signals. |
| 15 |
|
| 16 |
:param signals: signals to receive (e.g. ``signal.SIGINT``) |
| 17 |
:return: an asynchronous context manager for an asynchronous iterator which yields |
| 18 |
signal numbers |
| 19 |
:raises NoEventLoopError: if no supported asynchronous event loop is running in the |
| 20 |
current thread |
| 21 |
|
| 22 |
.. warning:: Windows does not support signals natively so it is best to avoid |
| 23 |
relying on this in cross-platform applications. |
| 24 |
|
| 25 |
.. warning:: On asyncio, this permanently replaces any previous signal handler for |
| 26 |
the given signals, as set via :meth:`~asyncio.loop.add_signal_handler`. |
| 27 |
|
| 28 |
""" |
| 29 |
return get_async_backend().open_signal_receiver(*signals) |