INNER CODE UNIT · Python
_PerThreadAttributes
micronaut-projects/micronaut-core · context-python/src/main/resources/META-INF/GRAALPY-VFS/micronaut-application/src/micronaut_asyncio.py:74
class _PerThreadAttributes:
"""Per-thread attribute storage that lives and dies with this context.
asyncio keeps its running loop, and the default policy its current loop, in ``threading.local``
objects. GraalPy stores those in a Java ``ThreadLocal`` of the calling thread, so an entry made
from a long-lived thread (a Netty event loop, a request thread, a test worker) keeps a closed
context reachable through the thread. A dict keyed by thread ident is released with the context.
"""
def __init__(self, **defaults):
object.__setattr__(self, "_defaults", defaults)
object.__setattr__(self, "_by_thread", {})
def __getattr__(self, name):
by_thread = object.__getattribute__(self, "_by_thread")
defaults = object.__getattribute__(self, "_defaults")
values = by_thread.get(threading.get_ident())
if values is not None and name in values: