Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close container on deletion #184

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Close container on deletion #184

wants to merge 4 commits into from

Conversation

agoscinski
Copy link
Contributor

In case the container is not used within a context and not correctly closed. The sessions are still correctly closed if the container is picked up by the garbage collection.

@agoscinski agoscinski requested a review from unkcpz February 11, 2025 09:52
@agoscinski agoscinski force-pushed the container-del branch 2 times, most recently from f4382c3 to 078caae Compare February 19, 2025 11:04
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.57%. Comparing base (6686ad0) to head (dfdc21c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #184   +/-   ##
=======================================
  Coverage   99.57%   99.57%           
=======================================
  Files          10       10           
  Lines        2118     2120    +2     
=======================================
+ Hits         2109     2111    +2     
  Misses          9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

In case the container is not used within a context and not correctly
closed. The sessions are now correctly closed if the container is picked
up by the garbage collection and deleted.
pylint cannot detect correctly nested generator types, therefore we ignore the
errors. Seems related pylint-dev/pylint#9252
@@ -1181,7 +1187,7 @@ def test_get_objects_stream_closes(temp_container, generate_random_data):
obj_md5s.keys(), skip_if_missing=True
) as triplets:
# I loop over the triplets, but I don't do anything
for _ in triplets:
for _ in triplets: # pylint: disable=not-an-iterable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pylint has been upgraded and causes these errors. I verified and the type ares are correct. There seems to be a issue related to this pylint-dev/pylint#9252

I put these into a separate commit

# We note the number of open of files, since Windows by default has some files open independent of the container
begin_test_open_files = len(current_process.open_files())

temp_container = Container(temp_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine for a test, but this means you didn't drop the container after, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right should everything should be wrapped by a finally and close the container

Comment on lines +170 to +172
def __del__(self) -> None:
"""Closes all connections on deletion."""
self.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you close the resources twice? For example, you already call close() and then you delete the container, will the close called again, what will happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should work, will add a test

@agoscinski agoscinski requested a review from unkcpz February 20, 2025 14:57
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good, thanks @agoscinski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants