[python-win32] Runnin Python app as service with separateconsole

Michael Li mli at deform.com
Fri Apr 14 23:23:36 CEST 2006


Hi, Mark

Thank you very much.
Now my python server works perfectly by adding
signal handler to intercept CTRL_LOGOFF_EVENT.

Best regards.
Michael Li



Michael Li wrote:
> Hi, Mark
> 
> Thank you very much.
> I will try it.
> 
> Best regards.
> Michael Li
> 
> Mark Hammond wrote:
> 
>> Your process is probably seeing the CTRL_LOGOFF_EVENT.
>> win32api.SetConsoleCtrlHandler will let you write a handler that 
>> ignores the
>> event.
>>
>> Mark
>>
>>
>>> -----Original Message-----
>>> From: Michael Li [mailto:mli at deform.com]
>>> Sent: Wednesday, 12 April 2006 9:03 AM
>>> To: Mark Hammond
>>> Cc: mli
>>> Subject: Re: [python-win32] Runnin Python app as service with
>>> separateconsole
>>>
>>>
>>> Hi, Mark
>>>
>>> Thank you very much.
>>>
>>>
>>> See my answers below.
>>>
>>> Mark Hammond wrote:
>>>
>>>>> "install_3d_app_service.cpp" is a program to install
>>>>> sftc3win.exe(sftc_3d_app_service.cpp)
>>>>> into a Windows' service. Inside sftc_3d_app_service.cpp, it will spawn
>>>>> "python".
>>>>> After reboot the machine, no problem, everything works fine, please 
>>>>> see
>>>>> attached
>>>>> picture python_running.JPG. The problem is that after I log off, the
>>>>> "python" has gone.
>>>>
>>>>
>>>>
>>>> I'm afraid you don't mention what this spawned Python is supposed to 
>>>> do.
>>>
>>>
>>> The spawned Python(using Twisted framework) runs 24X7 and
>>> when receives a request and spawn another command to run.
>>> I can my python scripts from DOS window, something like:
>>> C:\python23\python.exe my_server.py -3 --pid=pid.file --slog=log.file
>>> >run_log.file
>>>
>>>
>>>> Regardless though, it appears that exe is terminating, probably
>>>
>>>
>>> due to an
>>>
>>>> exception.  You need to arrange to see the output of this process to 
>>>> see
>>>> what went wrong.
>>>
>>>
>>> The python.exe is terminated only after log off any account.
>>> How do I debug/see the output of this process ?
>>>
>>>
>>>> If it is your .cpp implemented service that vanishes, then I've
>>>
>>>
>>> no idea what
>>>
>>>> it could be.
>>>
>>>
>>> sftc3win.exe(sftc_3d_app_service.cpp) will spawn
>>> "C:\python23\python.exe my_server.py -3 --pid=pid.file --slog=log.file
>>> >run_log.file"
>>>
>>> sftc3win.exe never vanishes. only python.exe vanished after log in/off
>>> any account.
>>>
>>> From attached picture python_running.JPG,
>>> you can see python.exe and sftc3win.exe are running as "SYSTEM".
>>>
>>>
>>>
>>>>
>>>>> Even if I log in as a non-administrative account, I log off, then the
>>>>> "python" has gone,
>>>>> even I am in the session of non-administrative account, I can not
>>>>> terminate(End Process)
>>>>> the "python" process. I am totally confused by this.
>>>>
>>>>
>>>>
>>>> It is normal (but frustrating) you can't kill it as the service
>>>
>>>
>>> is running
>>>
>>>> as LocalSystem.  You may have more luck setting it to run as your user.
>>>
>>>
>>> No, I do not want to kill the process. I want to prove that
>>> in the session of non-administrative account, you can not kill it,
>>> then how could "log off" kill it ?
>>>
>>>
>>>> I'm a little confused though, as you seem to say the problem is that 
>>>> the
>>>> python process has gone - but here you are failing to kill it.
>>>>
>>>>
>>>>
>>>>> I also can use Windows' Scheduled Tasks to add a task as "At System
>>>>> startup", I can run
>>>>> it as a service, but after I log in/log off any account, the "python"
>>>>> service has gone.
>>>>
>>>>
>>>>
>>>> The service (implemented in .cpp) has gone, or the child python
>>>
>>>
>>> executable?
>>> The service (implemented in .cpp) stays there always, only child
>>> python executable has gone.
>>>
>>>
>>>> Same answer as above though...
>>>>
>>>> Mark
>>>>
>>>
>>> From attached project file(VC6), you can build 
>>> ins3apse.exe/sftc3win.exe,
>>> this ins3apse.exe will install sftc3win.exe as a service,
>>> when a computer reboots, it will start the python.exe,
>>> until now, everything works fine. when I log in any account,
>>> no problem, everything works fine. Only after I log off any account,
>>> "python.exe" has gone.
>>>
>>>
>>> ==========
>>> This email message and any attachments are for the sole use of
>>> the intended recipients and may contain proprietary and/or
>>> confidential information which may be privileged or otherwise
>>> protected from disclosure. Any unauthorized review, use,
>>> disclosure or distribution is prohibited. If you are not the
>>> intended recipients, please contact the sender by reply email and
>>> destroy the original message and any copies of the message as
>>> well as any attachments to the original message.
>>>
>>
>>
> 

==========
This email message and any attachments are for the sole use of the intended recipients and may contain proprietary and/or confidential information which may be privileged or otherwise protected from disclosure. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipients, please contact the sender by reply email and destroy the original message and any copies of the message as well as any attachments to the original message.



More information about the Python-win32 mailing list