Tim Golden wrote:
Stef Mientki wrote:
How to determine if a process (known pid) os still running ?

Googling the web, I found 1 solution in killing the process,
but that's not what I want, I want to reuse the running process.

I could also ask a complete list of active processes,
but from my experiences that's quite slow.

Any better solutions ?

I'm not entirely sure what you're trying to achieve,
or what "reuse the running process" means.
ok, maybe I'm totally on the wrong track (I'm just an amateur),
because the GetExitCodeProcess, suggested by Julia,
gives an error "invalid handle"

What I want is quite simple:
from my program I want to show chm-help info,
so I've the following code

1      if not ( self.Win32_Viewer ) :
2 self.Win32_Viewer = win32help.HtmlHelp ( 0, str(CHM), win32help.HH_DISPLAY_INDEX, '' )
3      win32help.HtmlHelp ( self.Win32_Viewer,
4                           str(CHM),
5                           win32help.HH_DISPLAY_INDEX,
6                           str ( keyword ) )

Now this works well, until the user has closed the windows help window,
in which case line 3 crashes (of course).

Now I just did some experiments,
and saw that I could probably do enough by only performing line 2 (with a keyword),
as this, to my surprise, uses the same help window if one is already opened.
Is this indeed A corrrect way ?

thanks,
Stef


This WMI
snippet will tell you whether a given pid is running
or not. As you may know, WMI isn't the fastest thing
on earth, but it may be fast enough for you.

<code>
import wmi

pid = int (raw_input ("Enter PID:"))

c = wmi.WMI (find_classes=False)
for process in c.Win32_Process ([], ProcessId=pid):
  print "PID %s in use by %s" % (pid, process.Caption)
  break
else:
  print "PID %d not in use" % pid

</code>


TJG
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to