This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mark.Shannon, corona10, rhettinger, shihai1991, vstinner
Date 2020-12-26.22:09:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609020546.45.0.644583174752.issue40521@roundup.psfhosted.org>
In-reply-to
Content
> New changeset ea251806b8dffff11b30d2182af1e589caf88acf by Victor Stinner in branch 'master':
> bpo-40521: Per-interpreter interned strings (GH-20085)

I reopen the issue. This change caused a regression in attached interned_bug.py. Output:
---
$ ./python interned_bug.py 
Exception ignored deletion of interned string failed:
KeyError: 'out of memory'
python: Objects/unicodeobject.c:1946: unicode_dealloc: Assertion `Py_REFCNT(unicode) == 1' failed.
Abandon (core dumped)
---

Running "import xml.parsers.expat" in a subinterpreter causes two issues when the subinterpreter completes:

* pyexpat.errors and pyexpat.model dictionaries are cleared: all values set to None
* unicode_dealloc() logs an error on an interned string in the subinterpreter, because the string doesn't exist in the subinterpreter interned dictionary.

The interned string is created in the main interpreter and so stored in the main interpreter interned dictionary.

The string is stored in 2 dictionaries of pyexpat.errors dictionaries:

>>> pyexpat.errors.messages[1]
'out of memory'
>>> pyexpat.errors.codes['out of memory']
1

When the subinterpreter clears pyexpat.errors and pyexpat.model dictionaries, the interned string is deleted: unicode_dealloc() is called. But unicode_dealloc() fails to delete the interned string in the subinterpreter interned dictionary.

pyexpat.errors and pyexpat.model modules are cleared because they are stored as different names in sys.modules by Lib/xml/parsers/expat.py:

sys.modules['xml.parsers.expat.model'] = model
sys.modules['xml.parsers.expat.errors'] = errors
History
Date User Action Args
2020-12-26 22:09:06vstinnersetrecipients: + vstinner, rhettinger, Mark.Shannon, corona10, shihai1991
2020-12-26 22:09:06vstinnersetmessageid: <1609020546.45.0.644583174752.issue40521@roundup.psfhosted.org>
2020-12-26 22:09:06vstinnerlinkissue40521 messages
2020-12-26 22:09:06vstinnercreate