简体   繁体   中英

Open a Python script from another Python script in another shell

I am working currently on Raspbian. My Problem is i have a Python scrip with a infinite Loop that never should stop. In This script i want to call another script without the main script stopping. I tried different methodes to do this like:

import test1
test1.some_func()

or

execfile("test1.py")

or

import subprocess
subprocess.call("python test1.py")

I could start the test1.py script with these solutions, but the script that called it would stop working. So my question is how to start a second script without the first one to stop.

subprocess.call waits for the command to complete and thus blocks your loop. You should use something like process = subprocess.Popen(["python", "test1.py"]) . If you want to wait for the process to terminate, you can then call process.wait() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM