Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
945 views
in Technique[技术] by (71.8m points)

signals - Python: What is the default handling of SIGTERM?

What does Python do under the covers by default if it receives a SIGTERM but there is no signal handler registered for it?

question from:https://stackoverflow.com/questions/9930576/python-what-is-the-default-handling-of-sigterm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

    • This means that it will not raise an exception, or call the code in try: finally: blocks, or the __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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...