What does Python do under the covers by default if it receives a SIGTERM but there is no signal handler registered for it?
The SIGTERM signal is a generic signal used to cause program termination. Unlike SIGKILL , this signal can be blocked, handled, and ignored.
If a process receives SIGTERM, some other process sent that signal. SIGTERM is the signal that is typically used to administratively terminate a process. That's not a signal that the kernel would send, but that's the signal a process would typically send to terminate (gracefully) another process.
If time is non-zero, this function requests that a SIGALRM signal be sent to the process in time seconds. Any previously scheduled alarm is canceled (only one alarm can be scheduled at any time). The returned value is then the number of seconds before any previously set alarm was to have been delivered.
Building on the answer of Thomas Wouters, python does not register a handler for the SIGTERM signal. We can see this by doing:
In[23]: signal.SIG_DFL == signal.signal(signal.SIGTERM,signal.SIG_DFL) Out[23]: True
That means that the system will take the default action. On linux, the default action (according to the signal man page) for a SIGTERM is to terminate the process.
Terminating a process means that:
the process will simply not be allocated any more time slices during which it can execute code.
__exit__
method of context managers. It will not do those things because that particular python interpreter will never get the chance to execute another instruction. The process's memory and other resources (open files, network sockets, etc...) will be released back to the rest of the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With