How to run another Python program without holding up original

PythonChild Process

Python Problem Overview


What command in Python can be used to run another Python program?

It should not wait for the child process to terminate. Instead, it should continue on. It also does not need to remember its child processes.

Python Solutions


Solution 1 - Python

Use subprocess:

import subprocess

#code
prog = subprocess.Popen(['python', filename, args])
#more code

Solution 2 - Python

If the other Python program is importable, and the functionality you need can be called via a function, then it is preferable to use multiprocessing instead of subprocess, since the arguments can be passed as Python objects, instead of via strings:

import somescript
import multiprocessing as mp

proc = mp.Process(target=somescript.main, args=...)
proc.start()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPyRulezView Question on Stackoverflow
Solution 1 - PythonxgordView Answer on Stackoverflow
Solution 2 - PythonunutbuView Answer on Stackoverflow