Signal Handling

Signals

  • Usually correspond to external events and arrive asynchronously.
  • Example: Expiration of a timer, arrival of input, program fault.

The signal module

  • Provides functions for writing Unix-style signal handlers in Python.
     signal.signal(signalnum, handler)   # Set a signal handler
     signal.alarm(time)                  # Schedules a SIGALRM signal
     signal.pause()                      # Go to sleep until signal
     signal.getsignal(signalnum)         # Get signal handler

Supported signals (platform specific)

     SIGABRT      SIGFPE      SIGKILL    SIGSEGV    SIGTTOU
     SIGALRM      SIGHUP      SIGPIPE    SIGSTOP    SIGURG
     SIGBUS       SIGILL      SIGPOLL    SIGTERM    SIGUSR1
     SIGCHLD      SIGINT      SIGPROF    SIGTRAP    SIGUSR2
     SIGCLD       SIGIO       SIGPWR     SIGTSTP    SIGVTALRM
     SIGCONT      SIGIOT      SIGQUIT    SIGTTIN    SIGWINCH
     SIGXCPU      SIGXFSZ
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 57
July 17, 2000, beazley@cs.uchicago.edu
>>>