This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author turicas
Recipients damian.barabonkov, davin, keven425, pablogsal, pitrou, turicas, vinay0410
Date 2021-03-08.19:22:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615231336.97.0.15812245017.issue38119@roundup.psfhosted.org>
In-reply-to
Content
Based on changes at https://github.com/python/cpython/pull/15989 I've monkey-patched `multiprocessing.resource_tracker` so my current applications (running on Python 3.9.2) won't be affected. The code may be useful to others while the PR is not merged and we don't have a new release - you just need to call the `remove_shm_from_resource_tracker` function inside each Process target function.

----- >8 -----
from multiprocessing import resource_tracker


def remove_shm_from_resource_tracker():
    """Monkey-patch multiprocessing.resource_tracker so SharedMemory won't be tracked

    More details at: https://bugs.python.org/issue38119
    """

    def fix_register(name, rtype):
        if rtype == "shared_memory":
            return
        return resource_tracker._resource_tracker.register(self, name, rtype)
    resource_tracker.register = fix_register

    def fix_unregister(name, rtype):
        if rtype == "shared_memory":
            return
        return resource_tracker._resource_tracker.unregister(self, name, rtype)
    resource_tracker.unregister = fix_unregister

    if "shared_memory" in resource_tracker._CLEANUP_FUNCS:
        del resource_tracker._CLEANUP_FUNCS["shared_memory"]
----- 8< -----

There's a working example in attached file `mprt_monkeypatch.py` (if you comment the function calls on lines 28 and 37 the warnings will be shown).
History
Date User Action Args
2021-03-08 19:22:17turicassetrecipients: + turicas, pitrou, davin, pablogsal, vinay0410, damian.barabonkov, keven425
2021-03-08 19:22:16turicassetmessageid: <1615231336.97.0.15812245017.issue38119@roundup.psfhosted.org>
2021-03-08 19:22:16turicaslinkissue38119 messages
2021-03-08 19:22:16turicascreate