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