Python – Trap all signals

As of Python 3.5, the signal constants are defined as an enum, enabling a nicer approach: import signal catchable_sigs = set(signal.Signals) – {signal.SIGKILL, signal.SIGSTOP} for sig in catchable_sigs: signal.signal(sig, print) # Substitute handler of choice for `print`

Segmentation fault handling

The default action for things like SIGSEGV is to terminate your process but as you’ve installed a handler for it, it’ll call your handler overriding the default behavior. But the problem is segfaulting instruction may be retried after your handler finishes and if you haven’t taken measures to fix the first seg fault, the retried … Read more

How are asynchronous signal handlers executed on Linux?

These two explanations really aren’t contradictory if you take into account the fact that Linux hackers tend to be confused about the difference between a thread and a process, mainly due to the historical mistake of trying to pretend threads could be implemented as processes that share memory. 🙂 With that said, explanation #2 is … Read more

How to write a signal handler to catch SIGSEGV?

When your signal handler returns (assuming it doesn’t call exit or longjmp or something that prevents it from actually returning), the code will continue at the point the signal occurred, reexecuting the same instruction. Since at this point, the memory protection has not been changed, it will just throw the signal again, and you’ll be … Read more

Where should signal handlers live in a django project?

This was added to the documentation when Django 1.7 was released: Strictly speaking, signal handling and registration code can live anywhere you like, although it’s recommended to avoid the application’s root module and its models module to minimize side-effects of importing code. In practice, signal handlers are usually defined in a signals submodule of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)