I have a relatively simple service written in python that is doing asynchronous pulls from a pubsub subscription and then running a subprocess on the messages it receives. I'm currently just calling result() and blocking indefinitely and letting the background thread manage everything. What's the best and cleanest way to handle signals that the service may get? (E.g. I like to log startup and shutdown of the service). Should I just catch the signal and call cancel()?
Asked
Active
Viewed 505 times
0
-
Could you give further information on how you are handling signals right now, as well as further information on the code (code snippet) ? – Christopher Rodriguez Conde Jan 27 '20 at 09:11
1 Answers
0
Catching the signal and calling cancel() should work. This is done in the example Python quickstart for receiving messages.

Lauren
- 844
- 4
- 8
-
That approach only handles SIGINT, as it catches the `KeyboardInterrupt` exception. Any received SIGTERM will just kill the program without executing any clean-up code. – pietrodn Apr 17 '20 at 08:29