I'm developing a script that runs a program with other scripts over and over for testing purposes.
How it currently works is I have one Python script which I launch. That script calls the program and loads the other scripts. It kills the program after 60 seconds to launch the program again with the next script.
For some scripts, 60 seconds is too long, so I was wondering if I am able to set a FLAG variable (not in the main script), such that when the script finishes, it sets FLAG, so the main script and read FLAG and kill the process?
Thanks for the help, my writing may be confusing, so please let me know if you cannot fully understand.
-
1Why don't you launch them as subprocesses and use subprocess.Popen's wait() method to wait for them to finish?S.Lott– S.Lott2009年05月28日 23:19:58 +00:00Commented May 28, 2009 at 23:19
-
That would not work because the process never finishes. My script does this (Pseudo Code) ./Program.exe /home/user/Desktop/Script1.py So the Script1.py eventually finishes, but the Program.exe never really finishes... So subprocess.Popen wait() wouldn't work I don't think.hwrd– hwrd2009年05月28日 23:26:14 +00:00Commented May 28, 2009 at 23:26
-
Let me get this straight. mainscript.py executes program.exe, which in turn launches script1.py. program.exe doesn't end, but script1.py eventually does. You are looking for a way to detect when script1.py ends? Does script1.py end normally every time or sometimes error out?Paul– Paul2009年05月28日 23:50:59 +00:00Commented May 28, 2009 at 23:50
-
So basically, there is script1.py all the way through script50.py. Each one is different, and they MAY crash, so I also need a way to kill the process if it stalls (but that's a different issue).hwrd– hwrd2009年05月29日 00:01:49 +00:00Commented May 29, 2009 at 0:01
3 Answers 3
You could use atexit to write a small file (flag.txt) when script1.py exits. mainscript.py could regularly be checking for the existence of flag.txt and when it finds it, will kill program.exe and exit.
Edit: I've set persistent environment variables using this, but I only use it for python-based installation scripts. Usually I'm pretty shy about messing with the registry. (this is for windows btw)
2 Comments
This seems like a perfect use case for sockets, in particular asyncore.
Comments
You cannot use environment variables in this way. As you have discovered it is not persistent after the setting application completes
Comments
Explore related questions
See similar questions with these tags.