File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 1+ The :class: `~.lowlevel.TrioToken ` class can now be used as a target of a weak reference.
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ class TrioToken(metaclass=NoPublicConstructor):
145145
146146 """
147147
148- __slots__ = ("_reentry_queue" ,)
148+ __slots__ = ("_reentry_queue" , "__weakref__" )
149149
150150 def __init__ (self , reentry_queue ):
151151 self ._reentry_queue = reentry_queue
Original file line number Diff line number Diff line change 11import threading
22import queue as stdlib_queue
33import time
4+ import weakref
45
56import pytest
7+ from trio ._core import TrioToken , current_trio_token
68
79from .. import _core
810from .. import Event , CapacityLimiter , sleep
@@ -576,3 +578,10 @@ async def main():
576578
577579 _core .run (main )
578580 assert record == ["ok" ]
581+
582+
583+ async def test_trio_token_weak_referenceable ():
584+ token = current_trio_token ()
585+ assert isinstance (token , TrioToken )
586+ weak_reference = weakref .ref (token )
587+ assert token is weak_reference ()
You can’t perform that action at this time.
0 commit comments