Message388287
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). |
|
Date |
User |
Action |
Args |
2021-03-08 19:22:17 | turicas | set | recipients:
+ turicas, pitrou, davin, pablogsal, vinay0410, damian.barabonkov, keven425 |
2021-03-08 19:22:16 | turicas | set | messageid: <1615231336.97.0.15812245017.issue38119@roundup.psfhosted.org> |
2021-03-08 19:22:16 | turicas | link | issue38119 messages |
2021-03-08 19:22:16 | turicas | create | |
|