number passed in as command-line argument example - pp \system\processes\signal py ""catch signals in pythonpass signal number as command-line arguse "kill - pidshell command to send this process signalmost signal handlers restored by python after caught (see network scripting for sigchld details)on windowssignal module is availablebut it defines only few signal types thereand os kill is missing""import syssignaltime def now()return time ctime(time time()current time string def onsignal(signumstackframe)print('got signal'signum'at'now()python signal handler most handlers stay in effect signum int(sys argv[ ]signal signal(signumonsignalwhile truesignal pause(install signal handler wait for signals (orpassthere are only two signal module calls at work heresignal signal takes signal number and function object and installs that function to handle that signal number when it is raised python automatically restores most signal handlers when signals occurso there is no need to recall this function within the signal handler itself to reregister the handler that isexcept for sigchlda signal handler remains installed until explicitly reset ( by setting the handler to sig_dfl to restore default behavior or to sig_ign to ignore the signalsigchld behavior is platform specific signal pause makes the process sleep until the next signal is caught time sleep call is similar but doesn' work with signals on my linux boxit generates an interrupted system call error busy while truepass loop here would pause the scripttoobut may squander cpu resources here is what this script looks like running on cygwin on windows (it works the same on other unix-like platforms like linux) signal number to watch for ( is passed in on the command lineand the program is made to run in the background with an shell operator (available in most unix-like shells)[ :\pp \system\processes]python signal py [ ps pid ppid pgid winpid tty uid stime command con : : /usr/bin/bash con : : /usr/local/bin/python interprocess communication