Reputation: 721
I am making a python program (called A), where when the program recieves a Terminate Signal, it launches a different python program to run (called B). When A's program gets shutdown, the B program still needs to be still running in the background.
This is part of a cleanup function in a program I am writing for A. Also I don't have access to make any changes to B. (B is someone else's project, and not allowed to change it just build on top of it)
I been looking in using Popen or os.spawn function, when it receives the SIGTERM or SIGINT signals, but getting errors. When I tried os.spawn, it gave me an error saying that it could not find file name 'B.py programArgs', and it thought the progarmArgs was part of the filename.
Any ideas what I could do.
Code is something like this:
def main():
signal.signal(signal.SIGINT, onExit)
signal.signal(signal.SIGTERM, onExit)
def onExit(sig, frame):
pid = os.spawnl(os.P_NOWAIT, "usr/bin/python3", "python3", "/home/pi/filename", " programArg" )
Then it gives me the error:
Python3: can't open file '/home/pi/filename progarmArg': [Errno 2] No such file or directory
Upvotes: 0
Views: 59
Reputation: 2700
Assuming I'm not missing anything this should work
import subprocess
p1 = subprocess.Popen(['python','B location'], stdout=None)
Upvotes: 1