[python-win32] Re: wmi + pythonservice : multithreading issues

Aloys Baillet aloys at alamaison.fr
Tue Aug 17 10:29:15 CEST 2004


Thank you very much Thomas,
With your infos I found an exemple of using the win32pdh library for 
what I need:

<code>

import win32pdh, time

path = win32pdh.MakeCounterPath( \
	(None,"Process","Idle", None, -1, "% Processor Time") )

# open the query, and add the counter to the query
base = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(base, path)

# collect the data for the query object. We need to collect
# the query data
# twice to be able to calculate the % Processor Time
win32pdh.CollectQueryData(base)
time.sleep(0.1)
win32pdh.CollectQueryData(base)

# Get the formatted value of the counter
print win32pdh.GetFormattedCounterValue( \
	counter,win32pdh.PDH_FMT_LONG)[1]

</code>

And I understand that I have to call the counter 2 times.
But this script fails to run with the following error
(I use pywin32 build 202 and Python 2.3.4) :

<error>
Traceback (most recent call last):
   File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\pdhclient.py", line 
7, in ?
     counter = win32pdh.AddCounter(base, path)
pywintypes.error: (-1073738824, 'AddCounter', 'No error message is 
available')
</error>

I think I begin to know quite well Python, but I am new with pywin32... 
I am surely missing something simple here, but I can't figure it out!

Thanks for your help!

--
Aloys Baillet
R&D @ La Maison
www.alamaison.fr


Thomas Herve wrote:
> Aloys Baillet wrote:
> 
>> Hello,
> 
> 
> Hi,
> 
> [...]
> 
>>  And I wanted to give the user a real-time info on the percent of CPU 
>> used. The only way to go (I believe) is to use WMI.
> 
> 
> I can help here, as there's another way using win32pdh library. And I'm 
> (almost) sure it works in multithreading program. Although be careful as 
> there's some subtle issues with pdh (localized names, need to fetch the 
> counter 2 times to initialise it...).
> 



More information about the Python-win32 mailing list