1""" 2Substitute for the signal module when using a CFRunLoop. 3 4This module is generally only used to support: 5 PyObjCTools.AppHelper.installMachInterrupt() 6 7A mach port is opened and registered to the CFRunLoop. 8When a signal occurs the signal number is sent in a mach 9message to the CFRunLoop. The handler then causes Python 10code to get executed. 11 12In other words, Python's signal handling code does not wake 13reliably when not running Python code, but this does. 14""" 15 16import _machsignals 17__all__ = ['getsignal', 'signal'] 18 19def getsignal(signum): 20 """ 21 Return the signal handler for signal ``signum``. Returns ``None`` when 22 there is no signal handler for the signal. 23 """ 24 return _machsignals._signalmapping.get(signum) 25 26def signal(signum, handler): 27 """ 28 Install a new signal handler for ``signum``. Returns the old signal 29 handler (``None`` when there is no previous handler. 30 """ 31 rval = getsignal(signum) 32 _machsignals._signalmapping[signum] = handler 33 _machsignals.handleSignal(signum) 34 return rval 35