fix: asyncio: Task was destroyed but it is pending
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m48s
Build Worker Base and Application Images / deploy-stack (push) Successful in 18s
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m48s
Build Worker Base and Application Images / deploy-stack (push) Successful in 18s
This commit is contained in:
parent
5065e43837
commit
b8de5e191e
2 changed files with 16 additions and 10 deletions
|
@ -1108,6 +1108,8 @@ class DetectionPipeline:
|
|||
self.branch_processor.cleanup()
|
||||
|
||||
if self.license_plate_manager:
|
||||
asyncio.create_task(self.license_plate_manager.close())
|
||||
# Schedule cleanup task and track it to prevent warnings
|
||||
cleanup_task = asyncio.create_task(self.license_plate_manager.close())
|
||||
cleanup_task.add_done_callback(lambda _: None) # Suppress "Task exception was never retrieved"
|
||||
|
||||
logger.info("Detection pipeline cleaned up")
|
|
@ -123,20 +123,24 @@ class LicensePlateManager:
|
|||
|
||||
except asyncio.CancelledError:
|
||||
logger.info("License plate subscription task cancelled")
|
||||
# Properly close the async generator
|
||||
if listen_generator is not None:
|
||||
try:
|
||||
await listen_generator.aclose()
|
||||
except Exception as e:
|
||||
logger.debug(f"Error closing listen generator: {e}")
|
||||
# Don't try to close generator here - let it be handled by the context
|
||||
# The async generator will be properly closed by the cancellation mechanism
|
||||
raise # Re-raise to maintain proper cancellation semantics
|
||||
except Exception as e:
|
||||
logger.error(f"Error in license plate message listener: {e}", exc_info=True)
|
||||
# Properly close the async generator on error
|
||||
# Only attempt cleanup if it's not a cancellation
|
||||
finally:
|
||||
# Safe cleanup of async generator
|
||||
if listen_generator is not None:
|
||||
try:
|
||||
await listen_generator.aclose()
|
||||
# Check if we can safely close without conflicting with ongoing operations
|
||||
if hasattr(listen_generator, 'aclose') and not asyncio.current_task().cancelled():
|
||||
await listen_generator.aclose()
|
||||
except (RuntimeError, AttributeError) as e:
|
||||
# Generator is already closing or in invalid state - safe to ignore
|
||||
logger.debug(f"Generator cleanup skipped (safe): {e}")
|
||||
except Exception as e:
|
||||
logger.debug(f"Error closing listen generator: {e}")
|
||||
logger.debug(f"Generator cleanup error (non-critical): {e}")
|
||||
|
||||
async def _process_license_plate_result(self, data: Dict[str, Any]):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue