Skip to content

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

Closed

Description

@shailshouryya

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

Activity

  1. added a commit that references this issue on Jul 25, 2023
  2. added a commit that references this issue on Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions