Discussion:
[python-win32] fast test if (unknown) process is running ? Why not use Autoit ?
Stef Mientki
2010-08-06 11:27:31 UTC
Permalink
hello,

I wonder if there's a fast way to test if a process is running.

these are my experiences till so far:

1. win32pdh, not usefull, because it shows ths status of some ancient history

2. wmi, VERY SLOW: 1500 .. 2000 msec
import wmi
w = wmi.WMI()
processes = w.instances('Win32_Process')
instances = []
for process in processes :
if process.Name.lower() == name :
return process.ProcessId

3. Autoit, very fast: 10..20 msec
autoit = win32com.client.Dispatch ( "AutoItX3.Control" )
print autoit.ProcessExists ( process )

Are the better (faster) ways, without the use of AutoIt ?

Now this raises another question (please forgive my ignorance):
Why not use AutoIt always, instead of all the win32 libraries ?
AFAIK, the advantages of AutoIt:
- seems to be very fast
- is very well documented
- can be tested in a AutoIt friendly editor (Scite)
AFAIK the disadvantages:
- when distributing, you must add an extra file

thanks,
Stef Mientki
Tim Golden
2010-08-06 11:44:07 UTC
Permalink
Post by Stef Mientki
hello,
I wonder if there's a fast way to test if a process is running.
1. win32pdh, not usefull, because it shows ths status of some ancient history
2. wmi, VERY SLOW: 1500 .. 2000 msec
import wmi
w = wmi.WMI()
processes = w.instances('Win32_Process')
instances = []
return process.ProcessId
3. Autoit, very fast: 10..20 msec
autoit = win32com.client.Dispatch ( "AutoItX3.Control" )
print autoit.ProcessExists ( process )
Are the better (faster) ways, without the use of AutoIt ?
Why not use AutoIt always, instead of all the win32 libraries ?
- seems to be very fast
- is very well documented
- can be tested in a AutoIt friendly editor (Scite)
- when distributing, you must add an extra file
Try psutil (which uses the toolhelp DLL):

http://code.google.com/p/psutil/

<code>
import psutil

for p in psutil.process_iter ():
if p.name == "blah":
print p
break
else:
print "Not found"

</code>

TJG
Stef Mientki
2010-08-06 13:27:24 UTC
Permalink
thanks Tim,
Post by Tim Golden
<snip
http://code.google.com/p/psutil/
<code>
import psutil
print p
break
print "Not found"
</code>
yes that works quit well, just a little bit slower than AutoIt:
AutoIt: 0 .. 15 msec
psutils: 40 ..50 msec

thanks,
Stef Mientki
Post by Tim Golden
TJG
_______________________________________________
python-win32 mailing list
http://mail.python.org/mailman/listinfo/python-win32
sharpblade
2010-08-06 13:37:15 UTC
Permalink
You are not using the WMI efficiently. You iterate over every process to
Post by Stef Mientki
Post by Tim Golden
Post by Stef Mientki
import wmi
x = wmi.WMI()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
[<_wmi_object: \\TOM-PC\root\cimv2:Win32_Process.Handle="7052">]
t1 = time.time()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
print time.time()-t1
Post by Stef Mientki
Post by Tim Golden
Post by Stef Mientki
import time
test()
0.0829999446869
You can further reduce load times by requesting less data from WMI, i.e
t1 = time.time()
x.query("SELECT Handle FROM Win32_Process WHERE Name = 'xchat.exe'")
print time.time()-t1
Post by Stef Mientki
Post by Tim Golden
Post by Stef Mientki
test()
0.0599999427795
Post by Stef Mientki
thanks Tim,
Post by Tim Golden
<snip
http://code.google.com/p/psutil/
<code>
import psutil
print p
break
print "Not found"
</code>
AutoIt: 0 .. 15 msec
psutils: 40 ..50 msec
thanks,
Stef Mientki
Post by Tim Golden
TJG
_______________________________________________
python-win32 mailing list
http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
http://mail.python.org/mailman/listinfo/python-win32
Stef Mientki
2010-08-06 19:10:02 UTC
Permalink
thanks,
You are not using the WMI efficiently. You iterate over every process to test if only one is
Post by Stef Mientki
import wmi
x = wmi.WMI()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
[<_wmi_object: \\TOM-PC\root\cimv2:Win32_Process.Handle="7052">]
t1 = time.time()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
print time.time()-t1
Post by Stef Mientki
import time
test()
0.0829999446869
but that looks quit more complicated than psutils,
besides that I believe that psutils is platform independant.

cheers,
Stef
Tim Golden
2010-08-06 19:18:49 UTC
Permalink
Post by Stef Mientki
thanks,
You are not using the WMI efficiently. You iterate over every process to test if only one is
Post by Stef Mientki
import wmi
x = wmi.WMI()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
[<_wmi_object: \\TOM-PC\root\cimv2:Win32_Process.Handle="7052">]
t1 = time.time()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
print time.time()-t1
Post by Stef Mientki
import time
test()
0.0829999446869
but that looks quit more complicated than psutils,
besides that I believe that psutils is platform independant.
Well, just to phrase is slightly differently:

<code>
import wmi

c = wmi.WMI ()
for p in c.Win32_Process (Name="xchat.exe"):
print p
break
else:
print "Not found"

</code>

TJG
Stef Mientki
2010-08-06 22:34:55 UTC
Permalink
thanks Tim,
Post by sharpblade
Post by Stef Mientki
but that looks quit more complicated than psutils,
besides that I believe that psutils is platform independant.
0.0829999446869
<code>
import wmi
c = wmi.WMI ()
print p
break
print "Not found"
</code>
that looks much better,
but still windows only ;-)

cheers,
Stef
Post by sharpblade
TJG
Dahlstrom, Roger
2010-08-06 23:00:32 UTC
Permalink
Python-Win32...
As in win32
As in windows...

:-)




----- Original Message -----
From: python-win32-bounces+rdahlstrom=***@python.org <python-win32-bounces+rdahlstrom=***@python.org>
Cc: python-***@python.org <python-***@python.org>
Sent: Fri Aug 06 18:34:55 2010
Subject: Re: [python-win32] fast test if (unknown) process is running ? Why not use Autoit ?

thanks Tim,
Post by sharpblade
Post by Stef Mientki
but that looks quit more complicated than psutils,
besides that I believe that psutils is platform independant.
0.0829999446869
<code>
import wmi
c = wmi.WMI ()
print p
break
print "Not found"
</code>
that looks much better,
but still windows only ;-)

cheers,
Stef
Post by sharpblade
TJG
_______________________________________________
python-win32 mailing list
python-***@python.org
http://mail.python.org/mailman/listinfo/python-win32


DISCLAIMER:
This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. Direct Edge may, at its discretion, monitor and review the content of all e-mail communications.
Loading...