[python-win32] wmi + pythonservice : multithreading issues

Aloys Baillet aloys at alamaison.fr
Mon Aug 16 15:58:10 CEST 2004


Hello,

I recently discovered Tim Golden's wmi package, which is a very sweet 
addon to Mark Hammond's work. (BTW, Thank you very much to you two!)
But now I am stuck with a multi-threading issue.
Actually, I have build a distributed calculation framework (all in 
Python) based on a service running on several Win2K machines, which can 
communicate with each other via XML-RPC. 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.
But I noticed that I can use wmi only in the main thread of the 
application (if not, I get "x_wmi: 0x800401e4 - Syntaxe incorrecte" 
error messages). After some searches, I found in the MSDN site two lines 
about my problem:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/mmc_and_wmi.asp
<quote>
Threading Issues and Accessing WMI Data

To prevent their user interface from being blocked, snap-ins might 
choose to create a background thread for connecting to WMI. Note that 
snap-ins that obtain IWbemServices or IEnumWbemClassObject pointers in a 
background thread must marshal it into their main thread or any other 
dialog's thread.
</quote>

Unfortunately the service framework lauches SvcDoRun in a separate thread.
Has anybody an idea of how to bypass this Microsoft-related limitation?
Or maybe I am completely wrong and I could get the wmi data in any thread?
Or maybe I could hack pythonservice framework to run SvcDoRun in the 
main thread...

Thank you very much to share your thoughts!

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



More information about the Python-win32 mailing list