-
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled python exceptions do not result in non-zero exit codes in Win32Services #898
Comments
I think so. You can put more details like a sample? Do your service is based on the sample in the repository? Do you use the initialize, stop, run and state_chaged in the Handler class? |
Hi Marcel, I spent some time today replicating this. Using latest release ( 6.3 ) + the service sample i did the following.
In the scenario of an unhandled exception being raised in any of the Services methods ( Install / Start / Stop / Run / state/session change ) i would expect the process to exit with a None-Zero exit code so the windows recovery options can react to the services death. Having a quick look at the underlying implementation it looks like it will always return 0.... I hope that all makes sense / please say if i we can do anything to help out! |
Yes, when the service run is ok. cx_Freeze/source/bases/Win32Service.c Line 546 in f5be487
And LogPythonException returns -1 to cx_Freeze/source/bases/Win32Service.c Lines 579 to 583 in f5be487
Then you should use state_changed to catch this, and in Config.py it should be set to true (defaults to false)
|
Hi Marcel I tried ( i think! ) your suggestions but am still finding it always exits cleanly and doesn't trigger any recovery actions. (btw When searching this git project i can't find any references to I added a logger to the Handler class to try your suggestion, please find the modified service sample below :) With this +
Log Output...
Side note.... Re:
Wouldn't this return 0/None/Null? |
From a brief reading, it seems that it's possible to set the exit code from a stopped service in the call to According to the documentation for windows services status, it's possible to use the param If the function |
@darad @TechnicalPirate Can you test the @johron PR? To install the latest development build: |
Hey Marcel - thanks for flagging it - I will put it on my TODO list to test. Thank you for taking this Johron! :) |
Hi @marcelotduarte - I spent some time with Johron this week :)
|
@TechnicalPirate Did you test today's last commit? |
@marcelotduarte - Yep, we actually ended up on a call to go through and ensure we were both observing the same behaviour prior to making the change -> then confirming service recovery works as expected. There is one small nuance that's worth commenting on here - even with the latest commit - there is an implicit assumption that the service has to enter a running state for recovery measures to kick-in if the service process encounters an unhandled exception during execution. ( Something we discovered during testing ). But I can confirm that as of the latest commit a9e0df3 on that PR - everything is tested and working 👍 |
We have a python program cx-frozen into a Win32Service. The service must be running all the time and needs to recover from crashes automatically.
In face of unhandled python exceptions (ie fatal error), the running service seems to exit with a zero exit code leading the service state to STOPPED state. This render any of the Windows Service Recovery strategies ineffective as they only respond to non-zero ExitCodes.
As a workaround, we have resorted to a secondary service that's always checking the state of the frozen service. If it's in STOPPED state, it restarts it. That's an extra layer of management we need to maintain.
Can the service api change in a way that the exit codes reflects more closely the outcome of python program's execution?
The text was updated successfully, but these errors were encountered: