Simple question; How do you read the return value of a function that is called as a signal handler?
import signal
def SigHand(sig, frm):
return 'SomeValue'
signal.signal(signal.SIGCHLD, SigHand)
signal.pause()
Is there a way to read the return value 'SomeValue'
other than setting 开发者_JS百科it as a global?
You could create a simple class with a return value attribute.
>>> import signal
>>> class SignalHandler(object):
... def __init__(self):
... self.retval = None
... def handle(self, sig, frm):
... self.retval = sig
...
>>> s = SignalHandler()
>>> s.retval
>>> signal.signal(signal.SIGALRM, s.handle)
0
>>> signal.alarm(1)
0
>>> s.retval
14
精彩评论