0

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()?

JoeS
  • 381
  • 2
  • 4

1 Answers1

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