Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A python application will only quit when all non-daemonic threads have stopped. The watchdog thread is non-daemonic and so oresat_c3 can only quit once the watchdog thread has stopped. The watchdog thread will only quit if
event
is set, andevent
only gets set if oresat_c3 successfully makes it to the end ofmain()
.If oresat_c3 doesn't make it successfully to the end of
main()
(say an exception occurs during service initialization) then the watchdog thread will never stop, even though the main thread has, keeping the application running in a sort of unresponsive zombie mode. It is in fact so unresponsive that it ignores SIGINT (ctrl-c) so the only way to get it to stop is a SIGKILL, which is uncouth.Daemonic threads on the other hand will stop abruptly when the last non-daemon thread stops. This can be bad if resources in the thread need finalization but the only resource in the watchdog thread is a UDP socket, which the kernel will helpfully close for us. Setting the daemonic flag on the watchdog thread allows oresat_c3 to stop gracefully in exceptional circumstances.
An alternative to daemonic threads would be to wrap everything after starting the thread in a try-finally block but I felt that would be a bit more intrusive.