Repository navigation
Open
Labels
Description
Crash report
What happened?
When I run this code on Python 3.11 it runs fine, but if I import typing_minimal (or typing) in reader.py I get this error:
Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0x00007fff13ab6960)
Current thread 0x00003944 (most recent call first):
<no Python frame>
main.py:
import reader
from typing_minimal import Generic, TypeVar
VALUE = TypeVar("VALUE")
class BaseClass(Generic[VALUE]):
def __init__(self):
pass
class SubClass(BaseClass[VALUE]):
pass
reader.thread.start()reader.py:
from sys import stdin
from threading import Thread
# BUG: I get an error when I assign this:
# typing_minimal = __import__("typing_minimal")
thread = Thread(target=lambda: stdin.buffer.read(), daemon=True)typing_minimal.py:
from functools import lru_cache, wraps
def _tp_cache(func):
cached = lru_cache()(func)
@wraps(func)
def inner(*args, **kwds):
return cached(*args, **kwds)
return inner
class TypeVar:
def __init__(self, _):
pass
class _GenericAlias:
def __init__(self, origin):
self.origin = origin
def __eq__(self, other):
if isinstance(other, _GenericAlias):
return self.origin is other.origin
return NotImplemented
def __hash__(self):
return hash(self.origin)
def __mro_entries__(self, _):
return (self.origin,)
class Generic:
@_tp_cache
def __class_getitem__(cls, *_):
return _GenericAlias(cls)I don't understand how this is even possible.
CPython versions tested on:
3.11
Operating systems tested on:
macOS, Windows
Activity
sobolevn commentedon Mar 8, 2024
_lru_cache_wrapperusesRLock()inside, so this might be the cause when combined with a daemon thread.JelleZijlstra commentedon Mar 8, 2024
What is
typing_minimalhere? That's not in the stdlib and a cursory Google search didn't turn up anything.sobolevn commentedon Mar 8, 2024
It is a simplification of
typing.pyto make the bug more obvious :)JelleZijlstra commentedon Mar 8, 2024
It's in the comment... sorry I missed that.
nineteendo commentedon Mar 9, 2024
Any idea why importing
typing_minimalinreader.pymakes a difference?__import__("typing_minimal")instead oftyping_minimal = __import__("typing_minimal")works fine though.JelleZijlstra commentedon Mar 9, 2024
Possibly some new reference cycle gets created. Reminds me of #115874 though the symptom is different.
nineteendo commentedon Mar 13, 2024
Is there anything I can still help with?
sobolevn commentedon Mar 13, 2024
I used this example to reproduce the issue:
It still gives me:
So, now I think that this is a related to #113964
nineteendo commentedon Mar 13, 2024
The code at the top is simplified as much as possible. So this doesn't result in an error without the other changes (which is kind of strange too):
nineteendo commentedon Mar 13, 2024
This issue isn't so much about the interpreter crashing, but the fact that it crashes when I import
typing_minimalinreader.py.nineteendo commentedon Apr 10, 2024
JelleZijlstra commentedon Apr 10, 2024
It's a crash so it should be fixed. Hopefully someone will come along eventually and fix it, or other changes to the interpreter will fix this issue.