Crash report
Original report: https://gist.github.com/devdanzin/bf9fec4554c58c2a279b05b7ff8e6d9b (it produces the correct repro, but everything else is not correct, since it is AI generated and can be fuzzy).
Here's the real picture.
This class raises an error:
| classDistributionFinder(MetaPathFinder): |
| """ |
| A MetaPathFinder capable of discovering installed distributions. |
| |
| Custom providers should implement this interface in order to |
| supply metadata. |
| """ |
| |
| classContext: |
Repro:
importfaulthandler, importlib.metadatafaulthandler.enable()
from_testcapiimportset_nomemoryforstartinrange(40):
set_nomemory(start)
try:
importlib.metadata.metadata("f")
exceptBaseException:
passprint("done, no crash")Error:
Fatal Python error: _Py_Dealloc: Deallocator of type 'Context' cleared the current exception
Python runtime state: initialized
Stack (most recent call first):
File "/Users/sobolev/Desktop/cpython/Lib/importlib/metadata/__init__.py", line 465 in from_name
File "/Users/sobolev/Desktop/cpython/Lib/importlib/metadata/__init__.py", line 1091 in metadata
File "/Users/sobolev/Desktop/cpython/ex.py", line 7 in <module>
Extension modules: _testcapi (total: 1)
[1] 14108 abort ./python.exe ex.py
I tested this hack, no crash:
diff--gitLib/importlib/metadata/__init__.pyLib/importlib/metadata/__init__.pyindex32f4b7d2d6e..43ec93db749100644---Lib/importlib/metadata/__init__.py+++Lib/importlib/metadata/__init__.py
@@ -777,7+777,8 @@ classContext:
"""
def__init__(self, **kwargs):
-vars(self).update(kwargs)
+fork, vinkwargs.items():
+setattr(self, k, v)
@propertydefpath(self) ->list[str]:
But, this is clearly not a proper fix. Because for some reason the exception is cleared somewhere.
After:
» ./python.exe ex.py
object address : 0x20002128190
object refcount : 3
object type : 0x101267e70
object type name: MemoryError
object repr : lost sys.stderr
object address : 0x20002128110
object refcount : 3
object type : 0x101267e70
object type name: MemoryError
object repr : lost sys.stderr
Linked PRs
Crash report
Original report: https://gist.github.com/devdanzin/bf9fec4554c58c2a279b05b7ff8e6d9b (it produces the correct repro, but everything else is not correct, since it is AI generated and can be fuzzy).
Here's the real picture.
This class raises an error:
cpython/Lib/importlib/metadata/__init__.py
Lines 742 to 750 in 1785f4b
Repro:
Error:
I tested this hack, no crash:
But, this is clearly not a proper fix. Because for some reason the exception is cleared somewhere.
After:
Linked PRs