See when process exits in Windows XP

B

Brad Tilley

I've tested this function out and it works well... it'll loop until
ntbackup.exe has exited and then the script goes on to rename the
backup.bkf file and copy it to a file server. Having _never_ done this
before I thought it'd be wise to run this by comp.lang.python. I know
it's a simple and stupid way in which to monitor a process, but it works
for me... is it safe to do this? I don't want to get too complex.
Thanks, Brad

def wait_for_ntbackup_to_exit(procname):
while True:
try:
pids = win32pdhutil.FindPerformanceAttributesByName(procname)
if len(pids) > 0:
print pids
print len(pids)
print "ntbackup is running... waiting for it to exit."
continue
except:
return
 
B

Brad Tilley

I posted the wrong function... here's the one that works:

def wait_for_ntbackup_to_exit(procname):
while True:
try:
pids = win32pdhutil.FindPerformanceAttributesByName(procname)
if len(pids) > 0:
## If ntbackup is running, loop until it closes.
print pids
print len(pids)
print "ntbackup is running... waiting for it to exit."
continue
else:
## ntbackup is not running.
break
except:
return
 
T

Tobias Pfeiffer

Hi!

def wait_for_ntbackup_to_exit(procname):
while True:
try:
pids = \
win32pdhutil.FindPerformanceAttributesByName(procname)
if len(pids) > 0:
## If ntbackup is running, loop until it closes.
print pids
print len(pids)
print "ntbackup is running... waiting for it to
exit." continue
else:
## ntbackup is not running.
break
except:
return

I have no clue about that win32pdhutil thingy but if it returns a list
with pids, then why do you need the except statement? And it seems to me
that this loops as fast as the CPU is able to, so it actually steals away
other processe's CPU time. If you insert a time.sleep(0.5) statement (or
something similar), you can decrease the CPU usage to a minimum.

Bye
Tobias

PS. Why not use a simple:

while win32pdhutil.FindPerformanceAttributesByName(procname):
print "still running"
 
B

Brad Tilley

Tobias said:
Hi!




I have no clue about that win32pdhutil thingy but if it returns a list
with pids, then why do you need the except statement?

From trial and error, I found that if this function runs when ntbackup
isn't running that it would produce an error... that's the reason for
the except. I can reproduce it if you want the exact error message.

And it seems to me
that this loops as fast as the CPU is able to, so it actually steals away
other processe's CPU time. If you insert a time.sleep(0.5) statement (or
something similar), you can decrease the CPU usage to a minimum.

You're right, I did this and it helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top