Skip to content

Commit b63b5d7

Browse files
Update Doc/c-api/exceptions.rst
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent c34616c commit b63b5d7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Doc/c-api/exceptions.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,44 @@ Signal Handling
703703
.. versionchanged:: 3.14
704704
This function may now execute a remote debugger script, if remote
705705
debugging is enabled.
706+
Handle external interruptions, such as signals (including :kbd:`Ctrl-C`),
707+
or activating a debugger, whose processing has been delayed until it is safe
708+
to run Python code and/or raise exceptions.
709+
The function should be called by long-running C code frequently
710+
enough so that the response appears immediate to humans.
711+
712+
Handlers invoked by this function currently include:
713+
714+
- Signal handlers, including Python functions registered using
715+
the :mod:`signal` module.
716+
717+
Signal handlers are only run in the main thread of the main interpreter.
718+
719+
(This is where the function got the name: originally, signals
720+
were the only way to interrupt the interpreter.)
721+
722+
- Running the garbage collector, if necessary.
723+
724+
- Execuing a pending :ref:`remote debugger <remote-debugging>` script.
725+
726+
If any handler raises an exception, immediately return ``-1`` with that
727+
exception set.
728+
Any remaining interruptions are left to be processed on the next
729+
:c:func:`PyErr_CheckSignals()` invocation, if appropriate.
730+
731+
If all handlers finish successfully, or there are no handlers to run,
732+
return ``0``.
733+
734+
.. note::
735+
The default Python signal handler for :py:data:`signal.SIGINT` raises the
736+
:exc:`KeyboardInterrupt` exception.
737+
738+
.. versionchanged:: 3.12
739+
This function may now invoke the garbage collector.
740+
741+
.. versionchanged:: 3.14
742+
This function may now execute a remote debugger script, if remote
743+
debugging is enabled.
706744
707745
708746
.. c:function:: void PyErr_SetInterrupt()

0 commit comments

Comments
 (0)