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

Aloys Baillet aloys at alamaison.fr
Mon Aug 30 09:34:24 CEST 2004


Hello Tim,

Thank you for replying!
As you said, I allready managed to get some code working to retrieve 
performance infos using the registry directly.
And you have well understood my problem!
So I wrote a very tiny test you can maybe run on your config, just to 
see if it's just me that hear voices... ;)

<code>
import wmi
import threading

class lmPerformancesInfos(threading.Thread):
     def __init__(self):
         threading.Thread.__init__(self)
         print 'In Main Thread'
         c = wmi.WMI ()
         for process in c.Win32_Process ():
           print process.ProcessId, process.Name

     def run(self):
         print 'In Another Thread...'
         c = wmi.WMI ()
         while 1:
             for process in c.Win32_Process ():
               print process.ProcessId, process.Name

if __name__ == '__main__':
     perfs = lmPerformancesInfos()
     perfs.start()

</code>

And the result was:
<result>
In Main Thread
0 System Idle Process
8 System
[...]
1500 soffice.exe
1508 thunderbird.exe
1544 CMD.EXE
600 firefox.exe
1400 python.exe
In Another Thread...
D:\Python23\lib\site-packages\wmi.py:126: FutureWarning: hex()/oct() of 
negative int will return a signed string in Python 2.4 and up
   exception_string = ["%s - %s" % (hex (hresult_code), hresult_name)]
Exception in thread Thread-1:
Traceback (most recent call last):
   File "D:\Python23\lib\threading.py", line 436, in __bootstrap
     self.run()
   File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\wmi_thread.py", line 
14, in run
     c = wmi.WMI ()
   File "D:\Python23\Lib\site-packages\wmi.py", line 519, in __init__
     handle_com_error (error_info)
   File "D:\Python23\Lib\site-packages\wmi.py", line 131, in 
handle_com_error
     raise x_wmi, "\n".join (exception_string)
x_wmi: 0x800401e4 - Syntaxe incorrecte

</result>

Et voilà!
Maybe the fact that my Windows version is french causes problems?
Anyway, here is my config : Win2k SP4, 2 AMD CPUs, 2Gb RAM, Python 2.3.4
Don't hesitate to ask if you need more details!

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


Tim Golden wrote:
> Sorry, just got back off a three-week long course, so
> I've only just picked up this thread. It seems as though
> the dust has now settled on your original question and
> the responses. Could I just clarify the main points you
> initially raised re WMI / threading and Services.
> 
> As I understand it:
> 
> 1) You're using WMI in a service
> 
> 2) The service framework implicitly starts a 
>    separate thread inside which you're doing
>    some WMI work.
> 
> 3) As a result of this threading, a WMI syntax? 
>    error is thrown.
> 
> Have I understood correctly?
> 
> The thing is that I have successfully used WMI inside
> a (near-trivial) service, and -- although I can't at
> the moment find my code -- inside a (near-trivial)
> thread, both times without any problems. I'm running 
> Python 2.3 on Win2K.
> 
> Additionally, I can't really understand why a WMI
> syntax error should result, as opposed to some sort
> of runtime error.
> 
> If it's possible, I'd be interested to see the code
> which caused the error, or at least to narrow down
> the possibilities.
> 
> TJG
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star Internet. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________



More information about the Python-win32 mailing list