0

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.

asked May 28, 2009 at 22:48
4
  • 1
    Why don't you launch them as subprocesses and use subprocess.Popen's wait() method to wait for them to finish? Commented 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. Commented 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? Commented 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). Commented May 29, 2009 at 0:01

3 Answers 3

1

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)

answered May 28, 2009 at 23:55
Sign up to request clarification or add additional context in comments.

2 Comments

I found a way to set an environment variable, but it looks like it is not persistent...once Script1.py finishes, the variable is deleted. So I may end up doing this if all else fails...
If you want setting the environment variable to be persistent, you have to actually get into the registry. But I really don't recommend this approach for setting flags in a kind of IPC.
0

This seems like a perfect use case for sockets, in particular asyncore.

answered May 29, 2009 at 1:54

Comments

0

You cannot use environment variables in this way. As you have discovered it is not persistent after the setting application completes

answered Feb 23, 2010 at 14:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.