Menu

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

iafisher.com·Ian Fisher·about 2 months ago
#PrSLTN0I
#python#print#cpython#photo#article
Reading 0:00
15s threshold

“'Mr Bassington-Bassington has just telephoned, sir.'”

Python has two signal handlers

Blocking a signal is different than ignoring it

Python doesn't pass SA_RESTART

Safe signal idioms

Python signal handlers are unexpectedly reentrant

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

time.sleep and signal interrupts

Python siginterrupt is confusing

We learned earlier that because Python has two signal handlers , the onerous restrictions on what functions a signal handler may call do not apply to Python, because CPython does not call the user-supplied Python signal handler inside the low-level C signal handler, where those restrictions do apply, but arranges for it to be called later, when the interpreter is in a consistent state.

We also learned that Python signal handlers are unexpectedly reentrant – if a signal arrives while a Python signal handler is running, the signal handler can be called again in the middle of the first call.

What happens if a signal handler is reentered in the middle of…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.