473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error occurs when using wmi module in child thread

------------------sample code begin-------------------------

import threading

import wmi

def run(*args):
c = wmi.WMI ()
memory=c.Win32_LogicalMemoryConfiguration()[0]
info='Total Virtual Memory: '\
+str(int(memory.TotalVirtualMemory)/1024)\
+'MB'
print info

print "Begin run() in main thread"
run()

print "Begin run() in child thread"
thread=threading.Thread(target=run)
thread.start()
------------------sample code end---------------------------

------------------debug info begin--------------------------

Begin run() in main thread
Total Virtual Memory: 1375MB
Begin run() in child thread
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\my\Python24\lib\threading.py", line 444, in __bootstrap
self.run()
File "C:\my\Python24\lib\threading.py", line 424, in run
self.__target(*self.__args, **self.__kwargs)
File "F:\chen\code\SoftRepairer\script\test\test.py ", line 6, in run
c = wmi.WMI ()
File "C:\my\Python24\Lib\site-packages\wmi.py", line 971, in connect
handle_com_error (error_info)
File "C:\my\Python24\Lib\site-packages\wmi.py", line 219, in
handle_com_error
raise x_wmi, "\n".join (exception_string)
x_wmi: -0x7ffbfe1c - Invalid syntax

------------------debug info end----------------------------

------------------info I have found-------------------------

exception raised at:
file: Python24\Lib\site-packages\win32com\client\__init__.py
line: 88
code: moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
context:

def Moniker(Pathname, clsctx = pythoncom.CLSCTX_ALL):
"""
Python friendly version of GetObject's moniker functionality.
"""
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
dispatch = moniker.BindToObject(bindCtx, None,
pythoncom.IID_IDispatch)
return __WrapDispatch(dispatch, Pathname, clsctx = clsctx)

I have compaired the 'Pathname' parameter between main thread and child
thread
when running, they are the same.

-----------------------end----------------------------------

How can I solve the problem?
Thanks

Jul 11 '06 #1
2 2431

Chen Houwu wrote:
------------------sample code begin-------------------------

import threading

import wmi

def run(*args):
c = wmi.WMI ()
memory=c.Win32_LogicalMemoryConfiguration()[0]
info='Total Virtual Memory: '\
+str(int(memory.TotalVirtualMemory)/1024)\
+'MB'
print info

print "Begin run() in main thread"
run()

print "Begin run() in child thread"
thread=threading.Thread(target=run)
thread.start()
I had the same problem and wmi module author (Tim Golden) gave me the
solution which;
import pythoncom

# call this function after the run function definition
pythoncom.CoInitialize()
So your function becomes;

def run(*args):
pythoncom.CoInitialize()
c = wmi.WMI ()
memory=c.Win32_LogicalMemoryConfiguration()[0]
info='Total Virtual Memory: '\
+str(int(memory.TotalVirtualMemory)/1024)\
+'MB'
print info

-- Cheers

Jul 11 '06 #2
thanks to solve my big problem :-)
I will try it later.

Jul 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kamus of Kadizhar | last post by:
I have the following function which generates MD5 hashes for files on a local and remote server. The remote server has a little applet that runs from inetd and generates an MD5 hash given the file...
14
by: kosuke | last post by:
I keep getting the following error/warning message when using the python based program getmail4: /usr/lib/python2.3/optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will return a...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
0
by: Frank_00001 | last post by:
I'm trying to use Active Directory to get a list of users that are in the same directory as the logon user. I'm trying to do this as a Web App written in C# using Windows Security and...
3
by: Antti Keskinen | last post by:
Hello ppl ! Since this newsgroup is a place where Microsoft MVPs or related visit somewhat often, could someone give me an advice with possible causes of this error. Note that it does not happen...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
21
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
5
by: kyosohma | last post by:
Hi, I am trying to create a post logon script which does various tasks, like setup a printer based on location. While most of it works very fast, I have a second Python script that I run that...
0
by: Rafe | last post by:
Hi, This seems to be an old question, and I've read back a bit, but rather than assume the answer is "you can't do that", I'd thought I'd post my version of the question along with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.