I have a python app that builds a list of all subdirectories from the current directory, and then in turn runs a 'test.py' script from within each of these directories. I currently do this using os.system(). Is there any easy way of detecting apps that crashed, and terminating them if so? Ideally being able to set a time-out to wait for the application to finish would be good.
I think I could do it using CreateProcess, but, well, it just seems like overkill and that there'll be a much simpler method somewhere.
In article <3edb494b$0$12997$afc38...@news.easynet.co.uk>, "David Stubbs" <da...@snsys.com> wrote:
> I have a python app that builds a list of all subdirectories from the > current directory, and then in turn runs a 'test.py' script from within each > of these directories. I currently do this using os.system().
Sorry for not answering your question, but have you considered os.listdir() and os.path.isfile()?
I was a bit vague. I do use os.listdir() to build up the list. I meant that I execute a script from within each of these directories with the os.system() call. As the call to os.system() is blocking, I'd like some way to detect if the spawned process hangs, and if so recover control.
Does anyone know an easy way of traversing a list of python scripts, executing each one in turn, checking the return value, and also safeguarding against scripts that never return control back to the host script?
I'm just trying to create a simple test harness, and so far have it looking quite good except that if one of the individual tests crash then my test harness sits patiently waiting forever, which obviously isn't good as it then requires user intervention.
> In article <3edb494b$0$12997$afc38...@news.easynet.co.uk>, > "David Stubbs" <da...@snsys.com> wrote:
> > I have a python app that builds a list of all subdirectories from the > > current directory, and then in turn runs a 'test.py' script from within each > > of these directories. I currently do this using os.system().
> Sorry for not answering your question, but have you considered > os.listdir() and os.path.isfile()?
In article <3edb668b$0$13744$afc38...@news.easynet.co.uk>, "David Stubbs" <da...@snsys.com> wrote:
> Sorry,
> I was a bit vague. I do use os.listdir() to build up the list. I meant that > I execute a script from within each of these directories with the > os.system() call. As the call to os.system() is blocking, I'd like some way > to detect if the spawned process hangs, and if so recover control.
> Does anyone know an easy way of traversing a list of python scripts, > executing each one in turn, checking the return value, and also safeguarding > against scripts that never return control back to the host script?
> I'm just trying to create a simple test harness, and so far have it looking > quite good except that if one of the individual tests crash then my test > harness sits patiently waiting forever, which obviously isn't good as it > then requires user intervention.
Look at the popen2.py module. Either you can use it as-is, or (depending on your specific needs) you can use it as inspiration how to deal with external processes.
On Mon, Jun 02, 2003 at 01:55:39PM +0100, David Stubbs wrote: > Hi,
> I have a python app that builds a list of all subdirectories from the > current directory, and then in turn runs a 'test.py' script from within each > of these directories. I currently do this using os.system(). Is there any > easy way of detecting apps that crashed, and terminating them if so? Ideally > being able to set a time-out to wait for the application to finish would be > good.
> I think I could do it using CreateProcess, but, well, it just seems like > overkill and that there'll be a much simpler method somewhere.
As far as I know, you'll have to use the Windows-specific APIs if you want to do something like "kill this process if it takes longer than 30 seconds". On Unix, you would use fork+exec and os.kill(), but as far as I know these don't translate to the Windows world.
> I have a python app that builds a list of all subdirectories from the > current directory, and then in turn runs a 'test.py' script from within each > of these directories. I currently do this using os.system(). Is there any > easy way of detecting apps that crashed, and terminating them if so? Ideally > being able to set a time-out to wait for the application to finish would be > good.
> I think I could do it using CreateProcess, but, well, it just seems like > overkill and that there'll be a much simpler method somewhere.