Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Detect hung apps spawned from python
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Stubbs  
View profile  
 More options Jun 2 2003, 8:55 am
Newsgroups: comp.lang.python
From: "David Stubbs" <da...@snsys.com>
Date: Mon, 2 Jun 2003 13:55:39 +0100
Local: Mon, Jun 2 2003 8:55 am
Subject: Detect hung apps spawned from python
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.

Thanks,
Dave.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Just  
View profile  
 More options Jun 2 2003, 10:43 am
Newsgroups: comp.lang.python
From: Just <j...@xs4all.nl>
Date: Mon, 02 Jun 2003 16:43:50 +0200
Local: Mon, Jun 2 2003 10:43 am
Subject: Re: Detect hung apps spawned from python
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()?

Just


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Stubbs  
View profile  
 More options Jun 2 2003, 11:00 am
Newsgroups: comp.lang.python
From: "David Stubbs" <da...@snsys.com>
Date: Mon, 2 Jun 2003 16:00:25 +0100
Local: Mon, Jun 2 2003 11:00 am
Subject: Re: Detect hung apps spawned from python
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.

Thank again,
Dave.

"Just" <j...@xs4all.nl> wrote in message

news:just-8F68BC.16435002062003@news1.news.xs4all.nl...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Just  
View profile  
 More options Jun 2 2003, 11:17 am
Newsgroups: comp.lang.python
From: Just <j...@xs4all.nl>
Date: Mon, 02 Jun 2003 17:17:03 +0200
Local: Mon, Jun 2 2003 11:17 am
Subject: Re: Detect hung apps spawned from python
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.

Just


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Epler  
View profile  
 More options Jun 2 2003, 12:01 pm
Newsgroups: comp.lang.python
From: Jeff Epler <jep...@unpythonic.net>
Date: Mon, 2 Jun 2003 09:59:02 -0500
Local: Mon, Jun 2 2003 10:59 am
Subject: Re: Detect hung apps spawned from python

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.

Jeff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Stubbs  
View profile  
 More options Jun 3 2003, 8:42 am
Newsgroups: comp.lang.python
From: "David Stubbs" <da...@snsys.com>
Date: Tue, 3 Jun 2003 13:42:46 +0100
Local: Tues, Jun 3 2003 8:42 am
Subject: Re: Detect hung apps spawned from python
Thanks for your help. I decided to go the Win32 way. Here's my solution...

---
PROCESS_STILL_RUNNING = 259
def run_script(test_dir, timeout = 2):
    timeout = timeout * 60 # Convert the timeout param from minutes to
seconds
    os.chdir(test_dir)
    pinfo = win32process.CreateProcess(
        None, 'python.exe "' + test_dir + '\\test.py"', None, None, 0, 0,
        None, None, win32process.STARTUPINFO())

    retval = PROCESS_STILL_RUNNING
    while retval == PROCESS_STILL_RUNNING:
        time.sleep(0.25)
        timeout = timeout - 0.25
        if timeout <= 0:
            win32process.TerminateProcess(pinfo[0], 1)
            print "ERROR: Process timeout"
            break
        retval = win32process.GetExitCodeProcess(pinfo[0])
    os.chdir("..\\")
    return retval
---

Regards,
Dave Stubbs.

"David Stubbs" <da...@snsys.com> wrote in message

news:3edb494b$0$12997$afc38c87@news.easynet.co.uk...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »