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

Show attribute names in leak tracker #2291

Merged
merged 2 commits into from
Jul 23, 2024
Merged

Show attribute names in leak tracker #2291

merged 2 commits into from
Jul 23, 2024

Conversation

samtygier-stfc
Copy link
Collaborator

@samtygier-stfc samtygier-stfc commented Jul 23, 2024

Needed for 3.11 classes with lazy dictionaries

Issue

Needed for python 3.11 update ( see #2267 ), but works fine with 3.10

Description

In python 3.11 classes only create the dictionary object if needed ( faster-cpython/ideas#72 ).

When finding owners for objects in the leak tracker, and having an object held by a class like:

class ExampleObject:
    pass

class ExampleContainer:
    def __init__(self, obj):
        self.held_reference = obj

ob1 = ExampleObject()
container = ExampleContainer(ob1)

previously we gc.get_referrers(ob1) would give us the dict (i.e. container.__dict__) and from that we would find the key. Now gc.get_referrers(ob1) gives us the instance, and it is not clear which attribute it is.

The change add a case for a class, and adds the attribute name to extra_info. The act of looking at the __dict__ causes it to be created, so that we can get the name.

Also fix the test class name.

Testing

This fixes the leaktracker test when running with python 3.11 and above

Acceptance Criteria

Tests should pass

Documentation

release notes

@coveralls
Copy link

Coverage Status

coverage: 73.121% (+0.006%) from 73.115%
when pulling cf19e32 on 2267-leak-tracker
into 8cf298f on main.

@samtygier-stfc samtygier-stfc marked this pull request as ready for review July 23, 2024 15:19
@MikeSullivan7
Copy link
Collaborator

Using Python 3.12, the error relating to the leak tracker has been fixed and isn't showing anymore. I do get errors relating to mantidimaging/core/data/test/image_stack_test.py::ImageStackTest::test_cant_change_id and mantidimaging/gui/windows/main/test/strictdataset_test.py::StrictDatasetTest::test_cant_change_dataset_id but these are fixed by #2292

Copy link
Collaborator

@MikeSullivan7 MikeSullivan7 left a comment

Choose a reason for hiding this comment

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

See comment above!

@MikeSullivan7 MikeSullivan7 added this pull request to the merge queue Jul 23, 2024
Merged via the queue into main with commit 1eda58e Jul 23, 2024
8 checks passed
@MikeSullivan7 MikeSullivan7 deleted the 2267-leak-tracker branch July 23, 2024 21:04
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.

3 participants