views:

495

answers:

3

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.

+1  A: 

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)

bpowah
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...
hahuang65
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.
Ryan Ginstrom
A: 

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

Ryan Ginstrom
Thanks, not at work anymore, but I will try this tomorrow :)
hahuang65
A: 

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

David Sykes