>Is it legal to use Queue.put in a signal handle and Queue.get in the
main process (no thread)
hgPS: and if not is there a way to share data between a "main" and its
hgsignal in a safe way (write in signal and read in main)
The Queue module was designed to work in multithreaded contexts. I doubt it
will work as expected in a nonthreaded application. Given that your
application isn't multithreaded I suspect you can just modify an object that
both your signal handler and the rest of the application reference. In
particular, there's no reason your signal handler can't be a method of an
instance:
import signal
import time
class MyClass:
def __init__(self):
self.alarm_rang = False
signal.signal(signal.SIGALRM, self.ring_alarm)
signal.alarm(2)
def ring_alarm(self, sig, frame):
self.alarm_rang = True
obj = MyClass()
print obj.alarm_rang
time.sleep(4.0)
print obj.alarm_rang
Skip