52

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.

Alec
  • 6,521
  • 7
  • 23
  • 48
PyRulez
  • 9,505
  • 9
  • 37
  • 82

2 Answers2

31

use subprocess:

import subprocess

#code
prog = subprocess.Popen(['python', filename, args])
#more code
xgord
  • 3,719
  • 5
  • 24
  • 44
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()
unutbu
  • 711,858
  • 148
  • 1,594
  • 1,547