We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
文中说到terminate会立即杀死进程,但是输出如下下方的图,在p.terminate()之后,输出进程p.is_alive()返回了True,也就是进程还活着,但是在p.join()之后,再次输出p进程的状态却死了,经过自己尝试,terminate确实会立即去杀死进程,但是在主进程执行到p.is_alive()的时候p尚未被杀死所以导致了返回了True。看文章的时候我以为是和后面的join有关,后面尝试在terminate之后执行time.sleep(),发现与join并无关联。具体代码如下:
import multiprocessing from multiprocessing.dummy import Process import time def foo(): print("Starting func") time.sleep(0.1) if __name__ == "__main__": p = multiprocessing.Process(target=foo) print("Process before excution:", p, p.is_alive()) p.start() print("Process running :", p.is_alive()) p.terminate() time.sleep(0.1) # 如果没有这一行,下面一行的代码可能会返回True print("Process terminated:" , p.is_alive()) # process is alive p.join() print("Process joined:", p.is_alive()) # process is dead
The text was updated successfully, but these errors were encountered:
terminate 是发送 SIGTERM 信号,什么时候处理以及怎么处理取决于进程,所以可能不会立即退出。
Sorry, something went wrong.
这个还是留着吧供别人可以参考。
No branches or pull requests
文中说到terminate会立即杀死进程,但是输出如下下方的图,在p.terminate()之后,输出进程p.is_alive()返回了True,也就是进程还活着,但是在p.join()之后,再次输出p进程的状态却死了,经过自己尝试,terminate确实会立即去杀死进程,但是在主进程执行到p.is_alive()的时候p尚未被杀死所以导致了返回了True。看文章的时候我以为是和后面的join有关,后面尝试在terminate之后执行time.sleep(),发现与join并无关联。具体代码如下:
The text was updated successfully, but these errors were encountered: