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

Add rtype_cache to warnings.warn message when leaked objects found #106739

Closed
shailshouryya opened this issue Jul 14, 2023 · 0 comments
Closed

Add rtype_cache to warnings.warn message when leaked objects found #106739

shailshouryya opened this issue Jul 14, 2023 · 0 comments
Labels
type-feature A feature request or enhancement

Comments

@shailshouryya
Copy link
Contributor

shailshouryya commented Jul 14, 2023

Feature or enhancement

Add the rtype_cache (which is a set that includes all leaked objects of a particular type) to the warnings.warn message in Lib/multiprocessing/resource_tracker.py when any leaked objects are found to make debugging easier:

warnings.warn('resource_tracker: There appear to be %d '
'leaked %s objects to clean up at shutdown' %
(len(rtype_cache), rtype))

Pitch

When the resource_tracker module (Lib/multiprocessing/resource_tracker.py) finds leaked objects, the finally block in the main function includes the type of leaked objects and the number of leaked objects, but does not actually include the objects that are leaked. Adding the set of rtype_cache to the warnings.warn message will make debugging much more useful, as the names of the leaked objects could help more quickly identify what was leaked and/or why the leaked object was not properly cleaned up.

The permalink attached above links directly to the relevant code as it is currently implemented, but I'm adding it again below with some surrounding code for reference here:

    finally:
        # all processes have terminated; cleanup any remaining resources
        for rtype, rtype_cache in cache.items():
            if rtype_cache:
                try:
                    warnings.warn('resource_tracker: There appear to be %d '
                                  'leaked %s objects to clean up at shutdown' %
                                  (len(rtype_cache), rtype))
                except Exception:
                    pass

Previous discussion

A recent example of an issue where the additional context would have been useful is #104090, in which the current warning message is /workspace/cpython/Lib/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown.

Linked PRs

@shailshouryya shailshouryya added the type-feature A feature request or enhancement label Jul 14, 2023
pitrou pushed a commit that referenced this issue Jul 25, 2023
…bjects found (#106740)

Adding the `rtype_cache` to the `warnings.warn` message improves the
previous, somewhat vague message from

```
/Users/username/cpython/Lib/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown
```

to

```
/Users/username/cpython/Lib/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown: {'/mp-yor5cvj8', '/mp-10jx8eqr', '/mp-eobsx9tt', '/mp-0lml23vl', '/mp-9dgtsa_m', '/mp-frntyv4s'}
```

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
jtcave pushed a commit to jtcave/cpython that referenced this issue Jul 27, 2023
…aked objects found (python#106740)

Adding the `rtype_cache` to the `warnings.warn` message improves the
previous, somewhat vague message from

```
/Users/username/cpython/Lib/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown
```

to

```
/Users/username/cpython/Lib/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown: {'/mp-yor5cvj8', '/mp-10jx8eqr', '/mp-eobsx9tt', '/mp-0lml23vl', '/mp-9dgtsa_m', '/mp-frntyv4s'}
```

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant