Fix: avoid importing and calling close in __del__ during Python shutdown#7312
Draft
agoscinski wants to merge 1 commit intoaiidateam:mainfrom
Draft
Fix: avoid importing and calling close in __del__ during Python shutdown#7312agoscinski wants to merge 1 commit intoaiidateam:mainfrom
agoscinski wants to merge 1 commit intoaiidateam:mainfrom
Conversation
Two related fixes to prevent 'Exception ignored in __del__' errors during Python shutdown: 1. Move 'import warnings' to module level in RabbitmqBroker and StorageBackend to avoid ImportError when sys.meta_path is None during shutdown. 2. Guard __del__ with sys.is_finalizing() to skip the close() call during Python shutdown when asyncio/kiwipy event loop infrastructure is already torn down, preventing AttributeError in pytray's await_ method. During shutdown: - sys.meta_path becomes None, making imports unavailable - Module globals are set to None before garbage collection - asyncio.run_coroutine_threadsafe() fails with AttributeError By deferring the import and skipping close during finalization, we avoid both issues since the process is exiting anyway.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7312 +/- ##
==========================================
+ Coverage 79.85% 79.86% +0.01%
==========================================
Files 566 566
Lines 43947 43966 +19
==========================================
+ Hits 35088 35107 +19
Misses 8859 8859 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixing issue #7309
Two related fixes to prevent 'Exception ignored in del' errors during Python shutdown:
Move 'import warnings' to module level in RabbitmqBroker and StorageBackend to avoid ImportError when sys.meta_path is None during shutdown.
Guard del with sys.is_finalizing() to skip the close() call during Python shutdown when asyncio/kiwipy event loop infrastructure is already torn down, preventing AttributeError in pytray's await_ method.
During shutdown:
By deferring the import and skipping close during finalization, we avoid both issues since the process is exiting anyway.
TODO:
Upcoming changes:
PYTHONDEVMODE. This not a bug but a design consideration, it would be good if these warnings are logged somewhere but not showing them to the user makes sense. this requires some upcoming changes in the logger system