473,883 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ LogicalMemoryCo nfiguration()[0]
info='Total Virtual Memory: '\
+str(int(memory .TotalVirtualMe mory)/1024)\
+'MB'
print info

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

print "Begin run() in child thread"
thread=threadin g.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\S oftRepairer\scr ipt\test\test.p y", line 6, in run
c = wmi.WMI ()
File "C:\my\Python24 \Lib\site-packages\wmi.py ", line 971, in connect
handle_com_erro r (error_info)
File "C:\my\Python24 \Lib\site-packages\wmi.py ", line 219, in
handle_com_erro r
raise x_wmi, "\n".join (exception_stri ng)
x_wmi: -0x7ffbfe1c - Invalid syntax

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

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

exception raised at:
file: Python24\Lib\si te-packages\win32c om\client\__ini t__.py
line: 88
code: moniker, i, bindCtx = pythoncom.MkPar seDisplayName(P athname)
context:

def Moniker(Pathnam e, clsctx = pythoncom.CLSCT X_ALL):
"""
Python friendly version of GetObject's moniker functionality.
"""
moniker, i, bindCtx = pythoncom.MkPar seDisplayName(P athname)
dispatch = moniker.BindToO bject(bindCtx, None,
pythoncom.IID_I Dispatch)
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 2463

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

import threading

import wmi

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

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

print "Begin run() in child thread"
thread=threadin g.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.CoIni tialize()
So your function becomes;

def run(*args):
pythoncom.CoIni tialize()
c = wmi.WMI ()
memory=c.Win32_ LogicalMemoryCo nfiguration()[0]
info='Total Virtual Memory: '\
+str(int(memory .TotalVirtualMe mory)/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
2402
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 name. The problem is that it takes 2+ minutes to generate the MD5 hash, so this function takes about 5 minutes every time it is called. Since the first MD5 hash is generated on a remote machine, the local machine does nothing but wait for...
14
1942
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 signed string in Python 2.4 and up return ("<%s at 0x%x: %r>" I'm using python2.3.5 on a debian sid box. The getmail4 website/FAQ maintains that this is a bug in the optparse
21
4442
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 if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file...
0
1302
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 Impersonation. When running from the local host I have no problem; but when I try the same thing remotely I get the error "System.Runtime.InteropServices.COMException" on the second hit on Active Directory, the first hit works fine. I used to get the same...
3
2056
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 with the programs I write, but with Visual Studio .NET 2003 itself. It seems to appear only when I have the Visual Assist add-in installed. Removing the add-in fixes this error, but using VA is pretty much a necessity due to the bad functionality...
6
7454
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. The question is: after the ThreadAbortException is thrown, does the childThread continue run the remaining code in the catch block?
21
6907
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
5622
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 scans the PC using WMI (among other things) and writes the following to a database: Name, Username, Machine, IP, Login Date,CPU,Memory. The problem I have is that since I import WMI, it takes a long time and we have users complaining about it. So...
0
1916
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 reproducible error to illustrate my confusion. My problem is that I'm using Python inside XSI (a 3D graphics application). If I want to restart Python, I have to restart XSI. This is no small amount of time wasted.
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10767
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10422
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6008
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.