How to Start a Script as a Separate Process in Python
The Python programming language has an extensive library of built-in code modules. These modules address common programming tasks and can dramatically shorten program development time. For example, the Python standard library has a module named "subprocess" that allows you to run a script as a separate process using as little as one line of code. This can shorten application development times because you can call execute other scripts and programs from within your code.
Instructions
-
-
1
Open the IDLE text editor that comes with the Python download. The IDLE text editor is found in Program Files (or Applications for Macintosh), in the Python directory. A blank source code file opens in the IDLE text editor window.
-
2
Import the "subprocess" module by writing the following statement at the top of the source code file:
import subprocess
-
-
3
Declare a string that will store the executable command you want to run in as a separate process. For example, if you want to create a new instance of the Python script "scriptName.py." you could write the following:
args = "python scriptName.py"
-
4
Call the subprocess.Popen function. This will execute the command from the previous step. The syntax for this function looks like this:
p = subprocess.Popen(args)
-
5
Execute the program by pressing the F5 key. Python will run the script, which then executes the Python command prompt as a separate process.
-
1
Tips & Warnings
If you don't have Python on your computer, you can download it (see link in Resources).