diff --git a/src/apify/_actor.py b/src/apify/_actor.py index 9fc7ff1a..f4a3b0d2 100644 --- a/src/apify/_actor.py +++ b/src/apify/_actor.py @@ -249,11 +249,21 @@ async def finalize() -> None: if self._event_listeners_timeout: await self.event_manager.wait_for_all_listeners_to_complete(timeout=self._event_listeners_timeout) - await self.event_manager.__aexit__(None, None, None) - await self._charging_manager_implementation.__aexit__(None, None, None) + try: + await self.event_manager.__aexit__(None, None, None) + except Exception: + self.log.exception('Failed to exit event manager') + + try: + await self._charging_manager_implementation.__aexit__(None, None, None) + except Exception: + self.log.exception('Failed to exit charging manager') # Persist Actor state - await self._save_actor_state() + try: + await self._save_actor_state() + except Exception: + self.log.exception('Failed to save Actor state') try: await asyncio.wait_for(finalize(), self._cleanup_timeout.total_seconds())