Benjamin Peterson <benja...@python.org> wrote: > Adding PyGC_CollectIfEnabled() and calling it in Py_Finalize is probably > fine. I don't think the contract of PyGC_Collect itself (or gc.collect() > for that matter) should be changed. You might want to disable GC but > invoke it yourself.
Yes, that sounds okay to me. I poked around at the calls to PyGC_Collect() and _PyGC_CollectNoFail(). The cyclic garbage collector gets invoked at least three times during shutdown. Once by Py_FinalizeEx() and two times by PyImport_Cleanup(). That seems a bit exessively expensive to me. The collection time can be significant for programs with a lot of "container" objects in memory. The whole finalize/shutdown logic of the CPython interpreter could badly use some improvement. Currently it is a set of ugly hacks piled on top of each other. Now that we have PEP 3121, Extension Module Initialization and Finalization https://www.python.org/dev/peps/pep-3121/ we should be able to cleanup this mess. PyImport_Cleanup() is the main area of trouble. I don't think we should not be clearing sys.modules and we should certainly not be clearing module dicts. If there is some whippersnapper out there who wants to get their hands dirty with Python internals, fixing PyImport_Cleanup() would be a juicy project. Neil _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com