PyObjCTools.MachSignals – signal handling in a CFRunLoop

Substitute for the signal module when using a CFRunLoopRef.

This module is generally only used to support PyObjCTools.AppHelper.installMachInterrupt().

A mach port is opened and registered to the Run Loop. When a signal occurs the signal number is sent in a mach message to the Run Loop. The handler then causes Python code to get executed.

This is equivalent to the signal module, but that module doesn’t work promptly when a program is blocked waiting on a Run Loop.

PyObjCTools.MachSignals.getsignal(signum)

Query the current signal handler for signum.

Parameters:

signum (int) – Signal value to query,should be one of the SIG* constants from signal.

Returns:

None when there is no signal handler, handler function otherwise.

PyObjCTools.MachSignals.signal(signum, handler)

Install a new signal handler for signum.

Parameters:
  • signum (int) – Signal value to set,should be one of the SIG* constants from signal.

  • handler – Signal handler callable, should accept a single positional parameter, the signal number.

Returns:

The previous signal handler, or None when there is no previous handler.