Skip to content

Draft: Cancel cleanup tasks before stopping the main loop

Jeremiah Bonney requested to merge jbonney/cleanup-shutdown-fixes into master

Description

This makes two changes to facilitate a more orderly shutdown of cleanup when it receives a signal:

  1. Check for the asyncio.CancelledError exception and break out of the cleanup loop if it's raised
  2. Cancel each individual cleanup task in stop, which is what gets called on SIGTERM, before calling self._main_loop.stop().

This should make cancellations more reliable and prevent errors like RuntimeError('Event loop stopped before Future completed.'), which I've had happen in some cases.

Merge request reports