Title: bpo-36867: Create the resource_tracker before launching SharedMemoryManagers by pierreglaser · Pull Request #13276 · python/cpython · GitHub
Open Graph Title: bpo-36867: Create the resource_tracker before launching SharedMemoryManagers by pierreglaser · Pull Request #13276 · python/cpython
X Title: bpo-36867: Create the resource_tracker before launching SharedMemoryManagers by pierreglaser · Pull Request #13276 · python/cpython
Description: TLDR; The resource_tracker needs to be created before SharedMemoryManager processes are launched (which is not the case for managers created using fork) Take this example below: from multiprocessing.managers import SharedMemoryManager from multiprocessing import resource_tracker smm = SharedMemoryManager() smm.start() sl = smm.ShareableList(range(10)) smm.shutdown() This simple and legitimate python scripts results in a very noisy output: /home/pierreglaser/repos/cpython/Lib/multiprocessing/resource_tracker.py:198: UserWarning: resource_tracker: There appear to be 1 leaked shared_memory objects to clean up at shutdown warnings.warn('resource_tracker: There appear to be %d ' /home/pierreglaser/repos/cpython/Lib/multiprocessing/resource_tracker.py:211: UserWarning: resource_tracker: '/psm_3bfa242d': [Errno 2] No such file or directory: '/psm_3bfa242d' warnings.warn('resource_tracker: %r: %s' % (name, e)) Here is why it happens: smm.start() launches a new manager process. At this point in the main process, no resource_tracker is created if the manager is launched using fork. sl = smm.ShareableList(range(10)) does two things: First, it creates a new shared_memory object from the parent process. At creation, a resource_tracker.register call is done -> resource_tracker.ensure_running is done -> a new resource_tracker process is created. In addition, this resource_tracker now tracks sl. However, since the manager process was created before, it does not know that a new resource_tracker process was just created in the parent process.. Once sl is created, the SharedMemoryManager asks its SharedMemoryTracker ( which lives in the manager process) to track it. smm.shutdown shuts down the manager. It thus asks the SharedMemoryTracker to destroy sl, which it tracks. To do so, it first opens it (using a SharedMemory(name)) call, which itself triggers a resource_tracker.register call -> resource_tracker.ensure_running call in the manager process, where no resource_tracker exists yet! Thus, another ResourceTracker instance /process is created and starts tracking sl immediatly after, it unlinks sl. This sends an unregister call to the newly created resource_tracker. When the script ends however, nothing has been done to tell the original resource_tracker created in the parent process that sl was properly unlinked. The resource_tracker thus thinks a leak happened, and tells the user (first line of my output)). However, there was no leak, as sl was properly unlinked by the manager. Therefore, the cleanup attempt of the resource_tracker fails, resulting the second error. The solution to this problem is simply to create the right before the manager process is created. https://bugs.python.org/issue36867
Open Graph Description: TLDR; The resource_tracker needs to be created before SharedMemoryManager processes are launched (which is not the case for managers created using fork) Take this example below: from multiprocessin...
X Description: TLDR; The resource_tracker needs to be created before SharedMemoryManager processes are launched (which is not the case for managers created using fork) Take this example below: from multiprocessin...
Opengraph URL: https://github.com/python/cpython/pull/13276
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:89e9a680-b854-cf69-4ba7-8abc72582d13 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C700:2D5E27:368F74:48E289:6A51C108 |
| html-safe-nonce | af846d2bd3d31a1bbb67c691117ae739397f67a26ae597518d8c2470aae9f495 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzAwOjJENUUyNzozNjhGNzQ6NDhFMjg5OjZBNTFDMTA4IiwidmlzaXRvcl9pZCI6Ijc2OTkyNjY3OTg3NDc3NjI5NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b18bd16cbdd97fb5f300ae1cfa22c81eb8e919c77356f36bd4a3d7a744c7a6b7 |
| hovercard-subject-tag | pull_request:278232026 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/13276/files |
| twitter:image | https://avatars.githubusercontent.com/u/18555600?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/18555600?s=400&v=4 |
| og:image:alt | TLDR; The resource_tracker needs to be created before SharedMemoryManager processes are launched (which is not the case for managers created using fork) Take this example below: from multiprocessin... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width