Signal Handling

int PyErr_CheckSignals()

This function interacts with Python’s signal handling. It checks whether a signal has been sent to the processes and if so, invokes the corresponding signal handler. If the signal module is supported, this can invoke a signal handler written in Python. In all cases, the default effect for SIGINT is to raise the KeyboardInterrupt exception. If an exception is raised the error indicator is set and the function returns -1; otherwise the function returns 0. The error indicator may or may not be cleared if it was previously set.

void PyErr_SetInterrupt()

Simulate the effect of a SIGINT signal arriving. The next time PyErr_CheckSignals() is called, the Python signal handler for SIGINT will be called.

If SIGINT isn’t handled by Python (it was set to signal.SIG_DFL or signal.SIG_IGN), this function does nothing.

int PySignal_SetWakeupFd(int fd)

This utility function specifies a file descriptor to which the signal number is written as a single byte whenever a signal is received. fd must be non-blocking. It returns the previous such file descriptor.

The value -1 disables the feature; this is the initial state. This is equivalent to signal.set_wakeup_fd() in Python, but without any error checking. fd should be a valid file descriptor. The function should only be called from the main thread.

在 3.5 版更改: On Windows, the function now also supports socket handles.