[python-win32] Re: wmi + pythonservice : multithreading issues -> pdh returns an error

Aloys Baillet aloys at alamaison.fr
Tue Aug 17 11:05:32 CEST 2004


Hello all,

With some more searches, I discovered the win32pdhutil package, and I 
tried the sample example given in the win32pdhutil.py file:
<code>
import win32pdhutil
print win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes")
</code>

Unfortunately it returned me the same error:

<error>
Traceback (most recent call last):
   File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\pdhclient.py", line 
2, in ?
     print win32pdhutil.GetPerformanceAttributes("Memory", "Available 
Bytes")
   File "D:\Python23\Lib\site-packages\win32\lib\win32pdhutil.py", line 
55, in GetPerformanceAttributes
     hc = win32pdh.AddCounter(hq, path)
pywintypes.error: (-1073738824, 'AddCounter', 'No error message is 
available')
</error>

Just to remember, I am under Windows 2000 SP4 (french) and I use Python 
2.3.4 with pywin32 build 202.
Has anybody seen this error before? And if yes, how can I get rid of it?
Thank you for your attention!

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

Aloys Baillet wrote:
> 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