Windows service and pyc files

Laszlo Nagy gandalf at designaproduct.biz
Thu Apr 5 12:00:52 EDT 2007


>
> Have you tried the subprocess module for this rather than os.system?
> You might be able to pipe errors to a file with it. You might be able
> to use the traceback module for more verbose error catching too.
>   
Okay, I'm tried this instead of os.system:

def dumpexc(e):
import sys,traceback,StringIO
f = StringIO.StringIO('')
ei = sys.exc_info()
traceback.print_exception(ei[0],ei[1],ei[2],file=f)
return f.getvalue()

def spawn():
# ... setup mydir here....
os.chdir(mydir)
prog = os.path.join(mydir,"Application.py")
params = [sys.executable,prog]
logger.info("Spawing %s",str(params))
fout = file(os.path.join(mydir,'errorlog.txt'),'wb+')
try:
p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), 
stderr=fout.fileno())
except Exception, e:
logger.error(dumpexc(e))
return -1
retcode = p.wait()
logger.info("Subprocess exited, return code: %d",retcode)
fout.close()
return retcode

When I call spawn() from a service, this is written into the logfile:

2007-04-05 17:52:53,828 INFO .Spawner Spawing 
['C:\\Python25\\lib\\site-packages\\win32\\PythonService.exe', 
'T:\\Python\\Projects\\Test\\Application.py']
2007-04-05 17:52:53,828 ERROR .Spawner Traceback (most recent call last):
File "T:\Python\Projects\Test\Processor.py", line 40, in spawn_downloader
p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), 
stderr=fout.fileno())
File "C:\Python25\lib\subprocess.py", line 586, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\Python25\lib\subprocess.py", line 681, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python25\lib\subprocess.py", line 722, in _make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required


errorlog.txt is - of course - becomes an empty file.

When I call spawn() from an application, it works just fine. Any ideas?

Thanks,

Laszlo




More information about the Python-list mailing list