Compare commits
No commits in common. "e9f36891919f29dafe7305bf77de3d7f2cacecac" and "5ab642bdf04067ca491450a27d2e3489aad84a93" have entirely different histories.
e9f3689191
...
5ab642bdf0
|
@ -222,18 +222,16 @@ class _Cache:
|
||||||
task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED,
|
task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
async with mng as value:
|
||||||
async with mng as value:
|
_, no_more_users = cls.resources[ctx_key]
|
||||||
_, no_more_users = cls.resources[ctx_key]
|
cls.values[ctx_key] = value
|
||||||
try:
|
task_status.started(value)
|
||||||
cls.values[ctx_key] = value
|
try:
|
||||||
task_status.started(value)
|
await no_more_users.wait()
|
||||||
await no_more_users.wait()
|
finally:
|
||||||
finally:
|
# discard nursery ref so it won't be re-used (an error)?
|
||||||
value = cls.values.pop(ctx_key)
|
value = cls.values.pop(ctx_key)
|
||||||
finally:
|
cls.resources.pop(ctx_key)
|
||||||
# discard nursery ref so it won't be re-used (an error)?
|
|
||||||
cls.resources.pop(ctx_key)
|
|
||||||
|
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
|
|
|
@ -22,10 +22,6 @@ from __future__ import annotations
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
asynccontextmanager as acm,
|
asynccontextmanager as acm,
|
||||||
)
|
)
|
||||||
import inspect
|
|
||||||
from types import (
|
|
||||||
TracebackType,
|
|
||||||
)
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Type,
|
Type,
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
|
@ -67,66 +63,6 @@ def find_masked_excs(
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
_mask_cases: dict[
|
|
||||||
Type[Exception], # masked exc type
|
|
||||||
dict[
|
|
||||||
int, # inner-frame index into `inspect.getinnerframes()`
|
|
||||||
# `FrameInfo.function/filename: str`s to match
|
|
||||||
tuple[str, str],
|
|
||||||
],
|
|
||||||
] = {
|
|
||||||
trio.WouldBlock: {
|
|
||||||
# `trio.Lock.acquire()` has a checkpoint inside the
|
|
||||||
# `WouldBlock`-no_wait path's handler..
|
|
||||||
-5: { # "5th frame up" from checkpoint
|
|
||||||
'filename': 'trio/_sync.py',
|
|
||||||
'function': 'acquire',
|
|
||||||
# 'lineno': 605, # matters?
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def is_expected_masking_case(
|
|
||||||
cases: dict,
|
|
||||||
exc_ctx: Exception,
|
|
||||||
exc_match: BaseException,
|
|
||||||
|
|
||||||
) -> bool|inspect.FrameInfo:
|
|
||||||
'''
|
|
||||||
Determine whether the provided masked exception is from a known
|
|
||||||
bug/special/unintentional-`trio`-impl case which we do not wish
|
|
||||||
to unmask.
|
|
||||||
|
|
||||||
Return any guilty `inspect.FrameInfo` ow `False`.
|
|
||||||
|
|
||||||
'''
|
|
||||||
exc_tb: TracebackType = exc_match.__traceback__
|
|
||||||
if cases := _mask_cases.get(type(exc_ctx)):
|
|
||||||
inner: list[inspect.FrameInfo] = inspect.getinnerframes(exc_tb)
|
|
||||||
|
|
||||||
# from tractor.devx.debug import mk_pdb
|
|
||||||
# mk_pdb().set_trace()
|
|
||||||
for iframe, matchon in cases.items():
|
|
||||||
try:
|
|
||||||
masker_frame: inspect.FrameInfo = inner[iframe]
|
|
||||||
except IndexError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for field, in_field in matchon.items():
|
|
||||||
val = getattr(
|
|
||||||
masker_frame,
|
|
||||||
field,
|
|
||||||
)
|
|
||||||
if in_field not in val:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
return masker_frame
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# XXX, relevant discussion @ `trio`-core,
|
# XXX, relevant discussion @ `trio`-core,
|
||||||
# https://github.com/python-trio/trio/issues/455
|
# https://github.com/python-trio/trio/issues/455
|
||||||
#
|
#
|
||||||
|
@ -261,24 +197,6 @@ async def maybe_raise_from_masking_exc(
|
||||||
raise_unmasked
|
raise_unmasked
|
||||||
):
|
):
|
||||||
if len(masked) < 2:
|
if len(masked) < 2:
|
||||||
# don't unmask already known "special" cases..
|
|
||||||
if (
|
|
||||||
(cases := _mask_cases.get(type(exc_ctx)))
|
|
||||||
and
|
|
||||||
(masker_frame := is_expected_masking_case(
|
|
||||||
cases,
|
|
||||||
exc_ctx,
|
|
||||||
exc_match,
|
|
||||||
))
|
|
||||||
):
|
|
||||||
log.warning(
|
|
||||||
f'Ignoring already-known/non-ideally-valid masker code @\n'
|
|
||||||
f'{masker_frame}\n'
|
|
||||||
f'\n'
|
|
||||||
f'NOT raising {exc_ctx} from masker {exc_match!r}\n'
|
|
||||||
)
|
|
||||||
raise exc_match
|
|
||||||
|
|
||||||
raise exc_ctx from exc_match
|
raise exc_ctx from exc_match
|
||||||
|
|
||||||
# ??TODO, see above but, possibly unmasking sub-exc
|
# ??TODO, see above but, possibly unmasking sub-exc
|
||||||
|
|
Loading…
Reference in New Issue