[python-win32] What happens in a Python service in case of exception thrown?

Mark Hammond skippy.hammond at gmail.com
Thu Mar 3 00:37:25 EST 2022


On 3/03/2022 4:21 pm, Siyuan Ren wrote:
> I'm trying to subclass win32serviceutil.ServiceFramework in order to 
> create a Windows service in Python. I vaguely understand how each stage 
> of service works, but I wonder, what happens if any of the python code 
> throws an exception? Will the service stop, or put in an abnormal state 
> without recourse?

In general it will log a message to the eventlog and stop. Up until 
https://github.com/mhammond/pywin32/issues/1563 & 
https://github.com/mhammond/pywin32/pull/1566, it ended up reporting a 
normal `SERVICE_STOPPED` with an exit code of zero, but now it reports a 
non-zero code so you can configure it to auto-restart on exceptions.

HTH,

Mark


More information about the python-win32 mailing list