From da5e36bf0c383ddd92ba2b9fcdf8fc78ff81031a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 16 Dec 2021 11:00:57 -0500 Subject: [PATCH] Revert back to avoiding key errors on cancellation --- tractor/trionics/_mngrs.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tractor/trionics/_mngrs.py b/tractor/trionics/_mngrs.py index c9f596d..3834983 100644 --- a/tractor/trionics/_mngrs.py +++ b/tractor/trionics/_mngrs.py @@ -170,6 +170,7 @@ async def maybe_open_context( await _Cache.lock.acquire() ctx_key = (id(acm_func), key or tuple(kwargs.items())) + print(ctx_key) value = None try: @@ -214,6 +215,10 @@ async def maybe_open_context( if _Cache.users <= 0: log.info(f'De-allocating resource for {ctx_key}') - # terminate mngr nursery - _, no_more_users = _Cache.resources[ctx_key] - no_more_users.set() + # XXX: if we're cancelled we the entry may have never + # been entered since the nursery task was killed. + # _, no_more_users = _Cache.resources[ctx_key] + entry = _Cache.resources.get(ctx_key) + if entry: + _, no_more_users = entry + no_more_users.set()