problem querying WMI in a background thread

F

Fazan

I'm using Tim Golden's WMI implementation
(http://tgolden.sc.sabren.com/python/wmi.html) 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", ))
threading.Event().wait(2)
----

And here's the output:
----
callee: main thread
num processes: 57
callee: new thread
Unhandled exception in thread started by <function wmiTest at
0x009F7E30>
Traceback (most recent call last):
File "test.py", line 5, in wmiTest
processList = c.Win32_Process()
File "C:\svn\project\tool\wmi\0.6\wmi.py", line 404, in __call__
return self.wmi.query (wql)
File "C:\svn\project\tool\wmi\0.6\wmi.py", 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top