Search code examples
pythoncallraspbian

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.


Solution

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