tags:

views:

59

answers:

1

Hi,

How can I interrupt all running signals in a Python script? I would like something like signal.interrupt_all().

Is there any way to do that?

Thanks

+1  A: 

What exactly do you mean? Do you want to temporairly ignore a signal, or to completely ignore some kinds of signals?

Generally speaking, you can't "vanish" a signal once it has been generated. You either set its action to "ignore" or you block the signal, preventing it from being delivered, but you need to do this beforehand.

On POSIX systems, your options are (see Signal Concepts):

  • Ignore the signal by setting its handler to SIG_IGN. This will also cause pending signals to be ignored (see Signal Concepts: SIG_IGN).
  • Block a signal from delivery. The signal will remain pending but your process/thread won't receive it (until it is unblocked). Unfortunately, you can't block signals in Python: see the signal module documentation.

Note that you can't interrupt a signal handler (signal-catching function); this shouldn't be a problem, as signal handlers are expected to return quickly.

See also this question: Trapping Signals in Python.

Danilo Piazzalunga