You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RuntimeErrors upon interpreter shutdown due to garbage collection #762
I get this when opening certain Ramses snapshots, for example in the pynbody testdata, opening ramses_new_format_partial_output_00001: Expected behaviour or result
The expected behaviour is no warnings or errors when simply loading a snapshot and exiting. Instead I get
which appears multiple times (every time a shared memory array is getting garbage collected when python is shutting down).
Additionally, there are issues with the multiprocessing resource tracker as well:
/home/pavy/micromamba/envs/phd/lib/python3.12/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: Thereappeartobe16leakedshared_memoryobjectstocleanupatshutdownwarnings.warn('resource_tracker: There appear to be %d '
Setup:
Debian on Windows Subsystem for Linux
python 3.12.1
numpy 1.26.3
pynbody 1.5.2
Additional context
The first issue seems to be a new issue with python 3.12 (see python/cpython#104826). They started emitting errors when threads are spawned during interpreter finalisation. This error can be somewhat avoided by forcing the garbage collector to clean up the arrays before exiting by adding:
importgcdelsnapshotgc.collect()
before main() exits.
From what I read from the pynbody code is that these errors come from using the cleanup_callback approach to close and unlink the shared memory?
The second issue I don't fully understand but it seems related to this python issue (see https://bugs.python.org/issue39959) where multiple processes are trying to close the same shared memory. It seems to have a fix in the upcoming python 3.13 (see python/cpython#82300), so it might not be actionable until then.
Thanks very much for this helpful report. I was aware of some of this. The switch to using python's own shared memory support rather than relying on posix_ipc (#752) is behind this.
Unfortunately python's shared memory support has several limitations and shortcomings, including python/cpython#82300 as you describe. Indeed python 3.13 may help but there is a long road before that will be the minimum supported version so I hope to find fixes sooner.
The threading launch failure is a bug in a workaround a different limitation, and can be fixed fairly straightforwardly. The callback is indeed inappropriate when python is in the midst of shutting down. I will leave this issue open and update as and when.
Activity
apontzen commentedon Jan 19, 2024
Thanks very much for this helpful report. I was aware of some of this. The switch to using python's own shared memory support rather than relying on
posix_ipc(#752) is behind this.Unfortunately python's shared memory support has several limitations and shortcomings, including python/cpython#82300 as you describe. Indeed python 3.13 may help but there is a long road before that will be the minimum supported version so I hope to find fixes sooner.
The threading launch failure is a bug in a workaround a different limitation, and can be fixed fairly straightforwardly. The callback is indeed inappropriate when python is in the midst of shutting down. I will leave this issue open and update as and when.
Finish reverting shared memory support to posix_ipc module
apontzen commentedon Mar 23, 2024
Pull request #790 addresses this issue. Any comments gratefully received.
apontzen commentedon Mar 24, 2024
Fixed in #790