[issue44116] The _csv module can't be garbage-collected after _csv.register_dialect is called

Petr Viktorin report at bugs.python.org
Wed May 12 09:34:11 EDT 2021


New submission from Petr Viktorin <encukou at gmail.com>:

After `_csv.register_dialect` is called, the csv module is alive even after it's removed from sys.modules. It should be garbage-collected.
(It's not that big a deal: unloading _csv isn't something users should do. But it might be hiding a deeper issue.)

The following reproducer (for a debug build of Python) shows an increasing number of refcounts. (Importing `csv` is the easiest way to call _csv._register_dialect with a proper argument):


import sys
import gc

for i in range(10):
    import csv
    del sys.modules['_csv']
    del sys.modules['csv']
    del csv
    gc.collect()

    print(sys.gettotalrefcount())

----------
components: Extension Modules
messages: 393508
nosy: petr.viktorin
priority: normal
severity: normal
status: open
title: The _csv module can't be garbage-collected after _csv.register_dialect is called
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44116>
_______________________________________


More information about the Python-bugs-list mailing list