57

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.

0

2 Answers 2

33

Use subprocess:

import subprocess

#code
prog = subprocess.Popen(['python', filename, args])
#more code
Sign up to request clarification or add additional context in comments.

Comments

9

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()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.