[Python-Dev] PyGC_Collect ignores state of `enabled`
Ethan Furman
ethan at stoneleaf.us
Wed May 18 15:04:23 EDT 2016
On 05/18/2016 11:52 AM, Neil Schemenauer wrote:
> Benjamin Peterson 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.
Is there an issue filed for it?
--
~Ethan~
More information about the Python-Dev
mailing list