See when process exits in Windows XP

Tobias Pfeiffer me at
Sun Oct 17 12:29:44 CEST 2004


On 17 Okt 2004, Brad Tilley wrote:

> 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.


PS. Why not use a simple:

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

please send any mail to botedesschattens(at)web(dot)de

More information about the Python-list mailing list