What is signal handling? What is a signal in the context of programming mean? Is it like an interrupt in hardware, like a timer for example?
Can anyone give me an example in Python?
What is signal handling? What is a signal in the context of programming mean? Is it like an interrupt in hardware, like a timer for example?
Can anyone give me an example in Python?
A signal is typically exactly what it sounds like - it's a message delivered to a process. Most often when people say "signal," they're referring to a software interrupt that's sent to a process to trigger an event.
Think of it as message passing between processes - whether this means that one will abort a thread/run a shutdown method, etc.
see: http://docs.python.org/2/library/signal.html for an example:
import signal, os
def handler(signum, frame):
print 'Signal handler called with signal', signum
raise IOError("Couldn't open device!")
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(5)
# This open() may hang indefinitely
fd = os.open('/dev/ttyS0', os.O_RDWR)
signal.alarm(0) # Disable the alarm