DigiNews

Tech Watch by Johan Denoyer

← Back to articles

Is it safe to call `print` in a Python signal handler?

Quality: 8/10 Relevance: 9/10

Summary

The article examines the safety of calling print inside a Python signal handler. It explains CPython’s model where signal callbacks run outside the low-level handler and warns about reentrancy. A stress test demonstrates that printing from a signal handler can lead to a RuntimeError under extreme conditions, concluding that non-trivial work in signal handlers should be avoided.

🚀 Service construit par Johan Denoyer