Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a separate process

I want a script to start a new process, such that the new process continues running after the initial script exits. I expected that I could use multiprocessing.Process to start a new process, and set daemon=True so that the main script may exit while the created process continues running.

But it seems that the second process is silently terminated when the main script exits. Is this expected behavior, or am I doing something wrong?

like image 576
JacquesB Avatar asked Jun 13 '10 15:06

JacquesB


People also ask

How do you start a separate process in Python?

How to Start a Process in Python? To start a new process, or in other words, a new subprocess in Python, you need to use the Popen function call. It is possible to pass two parameters in the function call. The first parameter is the program you want to start, and the second is the file argument.

Can a process start another process?

Processes can only be started within the process they were created in. In the code provided, process2 was created in the main process, and yet tried to be started within another one ( process1 ). Also, processes cannot be restarted, so they should be created each time . start is used.

What is multiprocessing Freeze_support?

multiprocessing. freeze_support() This function will allow a frozen program to create and start new processes via the multiprocessing. Process class when the program is frozen for distribution on Windows. If the function is called and the program is not frozen for distribution, then it has no effect.


1 Answers

From the Python docs:

When a process exits, it attempts to terminate all of its daemonic child processes.

This is the expected behavior.

like image 149
Justin Ardini Avatar answered Sep 21 '22 06:09

Justin Ardini