Always pop `._Cache.resources` AFTER `mng.__aexit__()`
The correct ordering is to de-alloc the surrounding `service_n` + `trio.Event` **after** the `mng` teardown ensuring the `mng.__aexit__()` never can hit a ref-error if it touches either (like if a `tn` is passed to `maybe_open_context()`!final_eg_refinements
parent
b485297411
commit
6a82bab627
|
@ -223,16 +223,18 @@ class _Cache:
|
||||||
task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED,
|
task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
async with mng as value:
|
try:
|
||||||
_, no_more_users = cls.resources[ctx_key]
|
async with mng as value:
|
||||||
cls.values[ctx_key] = value
|
_, no_more_users = cls.resources[ctx_key]
|
||||||
task_status.started(value)
|
try:
|
||||||
try:
|
cls.values[ctx_key] = value
|
||||||
await no_more_users.wait()
|
task_status.started(value)
|
||||||
finally:
|
await no_more_users.wait()
|
||||||
# discard nursery ref so it won't be re-used (an error)?
|
finally:
|
||||||
value = cls.values.pop(ctx_key)
|
value = cls.values.pop(ctx_key)
|
||||||
cls.resources.pop(ctx_key)
|
finally:
|
||||||
|
# discard nursery ref so it won't be re-used (an error)?
|
||||||
|
cls.resources.pop(ctx_key)
|
||||||
|
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
|
|
Loading…
Reference in New Issue