Why calling print in a Python signal handler can crash your program
Is it safe to call print in a Python signal handler?
Python's signal handling model defers user handlers until the interpreter is safe, but reentrancy can still bite: if a signal arrives mid-print, the handler may call print again, triggering a RuntimeError. This article stress-tests the scenario, explains why it happens, and argues it's a curiosity rather than a practical threat—though it still advises against heavy work in handlers.
Running this program on my machine produced: RuntimeError: reentrant call inside <_io.BufferedWriter name='<stdout>'>