简体   繁体   English

Python多处理:如果父进程被杀死,子进程会挂起吗?

[英]Python multiprocessing: Will child process hang if the parent process was killed?

I need help to clarify some concepts. 我需要帮助来澄清一些概念。 Right now I'm using celery(a python scheduler) to run a task. 现在,我正在使用celery(python调度程序)来运行任务。 Since celery has time limit for a task(300s should be default) and my task is very likely to run longer, I decided to spawn a process inside that task to do the actual work. 由于芹菜有一项任务的时间限制(默认为300秒),而且我的任务很有可能会运行更长的时间,因此我决定在该任务中生成一个进程来完成实际工作。 However, what I don't know is that if during the execution of the task, I accidentally restart/stop celery server, will the process that spawned still working? 但是,我不知道的是,如果在执行任务期间,我不小心重新启动/停止了celery服务器,生成的进程是否仍将正常工作? Or it will become a zombie process? 否则它将成为僵尸进程? Please give me some details if possible. 如果可以的话,请给我一些细节。 Thanks! 谢谢!

Edit: One more question: when you do 编辑:另一个问题:当您这样做

p = Process(target=f, args=('test',))
p.start()

Does p become a child process for current process? p是否会成为当前进程的子进程? Or it just create an independent process? 还是只是创建一个独立的流程?

I'm afraid I can only answer your first question, not being very familiar with Celery, perhaps you can find the answer in the docs . 恐怕我只能回答您的第一个问题,对Celery不太熟悉,也许您可​​以在docs中找到答案。

Your question highlights the distinction between daemon and non-daemon threads. 您的问题强调了守护程序线程和非守护程序线程之间的区别。

Daemon threads are those which will not hang up the main program. 守护程序线程是那些不会挂断主程序的线程。 They will keep working until they finish, regardless of what the main program is doing. 无论主程序在做什么,它们都将继续工作直到完成。

Non-Daemon threads are just the opposite. 非守护程序线程正好相反。 They must be killed before the main program ends. 必须在主程序结束之前将其杀死。

This question/answer does a good job of explaining the difference and implications. 这个问题/答案很好地解释了区别和含义。

In the scope of your question, if your processes are daemon threads, they should be fine if you restart/stop your server. 在您的问题范围内,如果您的进程是守护程序线程,则在您重新启动/停止服务器时应该没问题。 However, if they aren't daemon threads, you shouldn't be able to stop the celery server (assuming my understanding of daemon threads is correct) 但是,如果它们不是守护程序线程,则您应该无法停止celery服务器(假设我对守护程序线程的理解是正确的)

Hopefully this helps 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python multiprocessing - 子进程阻塞父进程 - python multiprocessing - child process blocking parent process 如果父进程在 Python 中被杀死,则杀死子进程 - Kill Child Process if Parent is killed in Python 如果子进程被杀死,多处理池会挂起 - Multiprocessing Pool hangs if child process killed 主进程挂起子进程上的 Python 多处理与 time.sleep - Python multiprocessing vs time.sleep on main process hang child process python multiprocessing - 将子进程日志发送到在父进程中运行的 GUI - python multiprocessing - sending child process logging to GUI running in parent python多处理将子进程中的di​​ct传递回父进程 - python multiprocessing pass dict from child process back to parent python multiprocessing子进程触发父事件或方法 - python multiprocessing child process trigger parent event or method 使用python多处理库让父进程在子进程之前返回 - Let parent process return before child process using python multiprocessing library Python 多处理,子进程在发送前引发异常后,父进程在接收时挂起 - Python multiprocessing, parent process hangs at recv after child process raises exception before send 使用python multiprocessing子进程如何终止另一个子进程? - With python multiprocessing how can child process terminate another child process?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM