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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to