@@ -639,40 +639,44 @@ _test_textwrap_in_sys = 'textwrap' in sys.modules
639639% %
640640% % The ETS registry tracks what should be imported, and sys.modules
641641% % contains the actual imported modules.
642+ % %
643+ % % Note: Avoid modules that import C extensions with global state issues
644+ % % (e.g., statistics imports _decimal). Use json which has proper
645+ % % subinterpreter support. See https://github.com/python/cpython/issues/106078
642646registry_import_in_sys_modules_test (_Config ) ->
643647 % % Clear registry
644648 ok = py_import :clear_imports (),
645649
646650 % % Add to registry and import
647651 ok = py_import :ensure_imported (fractions ),
648- ok = py_import :ensure_imported (statistics ),
652+ ok = py_import :ensure_imported (json ),
649653
650654 % % Verify ETS registry has the entries
651655 Registry = py_import :all_imports (),
652656 ? assert (lists :member ({<<" fractions" >>, all }, Registry )),
653- ? assert (lists :member ({<<" statistics " >>, all }, Registry )),
657+ ? assert (lists :member ({<<" json " >>, all }, Registry )),
654658
655659 % % Use the modules to ensure they're imported
656660 {ok , _ } = py :call (fractions , 'Fraction' , [1 , 3 ]),
657- {ok , _ } = py :call (statistics , mean , [[1 , 2 , 3 , 4 , 5 ]]),
661+ {ok , _ } = py :call (json , dumps , [[1 , 2 , 3 ]]),
658662
659663 % % Verify both are in sys.modules by checking from Python
660664 ok = py :exec (<<"
661665import sys
662666_fractions_in_sys = 'fractions' in sys.modules
663- _statistics_in_sys = 'statistics ' in sys.modules
667+ _json_in_sys = 'json ' in sys.modules
664668_sys_modules_keys = list(sys.modules.keys())
665669" >>),
666670
667671 {ok , FractionsInSys } = py :eval (<<" _fractions_in_sys" >>),
668- {ok , StatsInSys } = py :eval (<<" _statistics_in_sys " >>),
672+ {ok , JsonInSys } = py :eval (<<" _json_in_sys " >>),
669673 ? assertEqual (true , FractionsInSys ),
670- ? assertEqual (true , StatsInSys ),
674+ ? assertEqual (true , JsonInSys ),
671675
672676 % % Get the list of modules in sys.modules that match our registry
673677 {ok , SysModulesList } = py :eval (<<" _sys_modules_keys" >>),
674678 ? assert (lists :member (<<" fractions" >>, SysModulesList )),
675- ? assert (lists :member (<<" statistics " >>, SysModulesList )),
679+ ? assert (lists :member (<<" json " >>, SysModulesList )),
676680
677681 ct :pal (" ETS registry and sys.modules are in sync" ).
678682
0 commit comments