Windows service and pyc files

Laszlo Nagy gandalf at designaproduct.biz
Thu Apr 5 12:50:16 EDT 2007


> 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
>
>   
Okay, here is what I learnt:

1. subprocess.Popen cannot redirect stderr and stdout when called from a 
win32 service. This is not documented, and makes debugging almost 
impossible.
2. sys.executable becomes "pythonservice.exe" inside a win32 service.

If I specify  r"C:\Python25\python.exe" instead of sys.executable, and 
if I do not specify stdout and stderr parameters for subprocess.Popen, 
then my program  starts to work. Here arises the question: how can I 
find r"C:\Python25\python.exe" from inside a win32 service? Can I use this:

interpreter = os.path.join(  os.path.split(sys.executable),[0], 
os.sep,os.sep,os.sep,'Python.exe' )

Is it safe? Please advise.
Thanks,

   Laszlo





More information about the Python-list mailing list