utils.py: explicitly convert module keys to a list
Compare changes
+ 1
− 1
Maintenance will be performed on git.ligo.org, containers.ligo.org, and docs.ligo.org on Tuesday 22 April 2025 starting at approximately 9am PDT. It is expected to take around 30 minutes and there will be several periods of downtime throughout the maintenance. Please address any comments, concerns, or questions to the helpdesk. This maintenance will be upgrading the GitLab database in order to be ready for the migration.
For some reason when I locally run my test suite for CWInPy it fails when using the loaded_modules_dict
function in utils.py
. The error given is:
cwinpy/hierarchical.py:1428: in sample
self._result = bilby.run_sampler(
../../miniconda3/envs/cwinpy/lib/python3.8/site-packages/bilby/core/sampler/__init__.py:145: in run_sampler
meta_data["loaded_modules"] = loaded_modules_dict()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def loaded_modules_dict():
module_names = sys.modules.keys()
vdict = {}
print(module_names)
> for key in module_names:
E RuntimeError: dictionary changed size during iteration
../../miniconda3/envs/cwinpy/lib/python3.8/site-packages/bilby/core/utils.py:1277: RuntimeError
so it's complaining about a dictionary size changing during the loop.
I seem to be able to fix this by explicitly setting:
module_names = list(sys.modules.keys())
I'm not sure why I'm seeing the error, but this fix seems to be otherwise harmless.