python / temporarily blocking signals

python / temporarily blocking signals

  • Written by
    Walter Doekes
  • Published on

There is no way to “block” signals temporarily from critical sections (since this is not supported by all Unix flavors). Says the python signal module manual.

But I’m using Linux, where it is possible to block signals, so I don’t think that limitation applies. And it doesn’t.

pysigset takes the burden off calling sigprocmask(2) through ctypes and provides a “pythonic” interface to temporarily blocking signals in python.

from signal import SIGINT, SIGTERM
from pysigset import suspended_signals

with suspended_signals(SIGINT, SIGTERM):
    # Signals are blocked here...
    pass

# Any signals that were blocked are now fired.

Get pysigset on github or through pip:
pip install git+https://github.com/ossobv/pysigset.git


Back to overview Newer post: python / twisted / exec environment Older post: darwin / sed / limited regular expressions