Importing WMI in a child Thread throws an error
Tim Golden
mail at timgolden.me.uk
Tue Feb 27 16:32:08 EST 2007
kyosohma at gmail.com wrote:
> The problem I have is that since I import WMI, it takes a long time
> and we have users complaining about it. So I stuck the import
> statement into a separate thread and set it to a daemon so it could do
> its thing in the background and the rest of the script would finish
> and exit.
Two things:
1) If you run WMI in a thread, you'll need to call
pythoncom.CoInitialize first:
<code>
import pythoncom
import wmi
pythoncom.CoInitialize ()
c = wmi.WMI ()
#
# do things
#
pythoncom.CoUninitialize ()
</code>
2) If you need a bit of speed running WMI, see the post
I sent a few days ago to someone else:
http://mail.python.org/pipermail/python-win32/2007-February/005550.html
TJG
More information about the Python-list
mailing list