#64: Random ImportError when using win32com.client
--------------------------+-------------------------------------------------
Id: 64 | Status: new
Component: PyInstaller | Modified: Mon Jul 31 01:27:39 2006
Severity: major | Milestone: PyInstaller 1.0
Priority: high | Version: PyInstaller 1.1 (Windows)
Owner: giovannibajo | Reporter: openticket
--------------------------+-------------------------------------------------
I am using the wmi module that utilizes win32com.client's GetObject() and
Dispatch(). I will randomly at runtime get an ImportError exception.
What is strange is this error does not happen every time I am including
the traceback and also my source code. Thanks for any help!
Traceback (most recent call last):
File "<string>", line 34, in ?
File "C:\Python24\pyinstaller\iu.py", line 312, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python24\pyinstaller\iu.py", line 382, in doimport
mod = director.getmod(nm)
File "C:\Python24\pyinstaller\iu.py", line 215, in getmod
mod = owner.getmod(nm)
File "C:\Python24\pyinstaller\archive.py", line 381, in getmod
raise ImportError, "PYZ entry '%s' (%s) is not a valid code object" %
(nm, r
epr(co))
ImportError: PYZ entry 'win32com' (2j) is not a valid code object
import os, sys, wmi
from subprocess import *
def getJavaPids():
pids = []
for p in c.Win32_Process (name='java.exe'):
pids.append(str(p.ProcessId))
return pids
def getNewJavaPid(l1, l2):
for p in l2:
if p not in l1:
return p
return '0' #error
def Stop(fn):
try:
f = open(fn,'r')
PID = f.read()
f.close()
for process in c.Win32_Process (name='java.exe'):
if process.ProcessID == int(PID):
process.Terminate ()
print prog+' at PID='+PID+' stopped.\n'
os.remove(fn)
except IOError:
pass #process not running
#------ Start Program
c = wmi.WMI ()
os.system('cls')
prog = sys.argv[1]
fn = prog.split('.')[0]+'.pid.'
if len(sys.argv) >= 3:
if sys.argv[2].lower() == 'stop':
Stop(fn)
sys.exit()
elif sys.argv[2].lower() == 'start':
Stop(fn)
jPids1 = getJavaPids()
p = Popen(prog)
jPids2 = getJavaPids()
PID = getNewJavaPid(jPids1, jPids2)
f = open(fn,'w')
f.write(PID)
f.close()
print prog+' at PID='+PID+' started.\n'
--
Ticket URL: <http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi/ticket/64>
PyInstaller <http://pyinstaller.hpcf.upr.edu>
PyInstaller
_______________________________________________
PyInstaller mailing list
[email protected]
http://lists.hpcf.upr.edu/mailman/listinfo/pyinstaller