By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,544 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,544 IT Pros & Developers. It's quick & easy.

problem querying WMI in a background thread

P: n/a
I'm using Tim Golden's WMI implementation
( version 0.6 along with
pywin32 build 202. I'm able to successfully query WMI in the main
thread but not in a separate thread.

Here's a little snippet of sample code that fails for me:
import thread, threading, wmi

def wmiTest(c, callee):
print "callee: " + callee
processList = c.Win32_Process()
print "num processes: %d" % len(processList)

if __name__ == '__main__':
c = wmi.WMI()
# invoke WMI in the main thread
wmiTest(c, "main thread")

# invoke WMI in a separate thread
thread.start_new_thread(wmiTest, (c, "new thread", ))

And here's the output:
callee: main thread
num processes: 57
callee: new thread
Unhandled exception in thread started by <function wmiTest at
Traceback (most recent call last):
File "", line 5, in wmiTest
processList = c.Win32_Process()
File "C:\svn\project\tool\wmi\0.6\", line 404, in __call__
return self.wmi.query (wql)
File "C:\svn\project\tool\wmi\0.6\", line 583, in query
raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147352567

Notice that calling wmiTest() from the main thread works and the list
of Win32_Process objects is returned. Calling it using
thread.start_new_thread() causes an exception to be thrown. I've also
tried instantiating the WMI object inside wmiTest() instead of passing
it in as a parameter; this also fails but with a different exception.

Has anyone seen this type of problem before? TIA
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.