Compare commits
4 Commits
4c3c3e4b56
...
f067cf48a7
Author | SHA1 | Date |
---|---|---|
Tyler Goodlet | f067cf48a7 | |
Tyler Goodlet | c56d4b0a79 | |
Tyler Goodlet | 7cafb59ab7 | |
Tyler Goodlet | 7458f99733 |
|
@ -939,6 +939,7 @@ async def tell_little_bro(
|
|||
def test_peer_spawns_and_cancels_service_subactor(
|
||||
debug_mode: bool,
|
||||
raise_client_error: str,
|
||||
reg_addr: tuple[str, int],
|
||||
):
|
||||
# NOTE: this tests for the modden `mod wks open piker` bug
|
||||
# discovered as part of implementing workspace ctx
|
||||
|
@ -956,6 +957,7 @@ def test_peer_spawns_and_cancels_service_subactor(
|
|||
async with tractor.open_nursery(
|
||||
# NOTE: to halt the peer tasks on ctxc, uncomment this.
|
||||
debug_mode=debug_mode,
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
server: Portal = await an.start_actor(
|
||||
(server_name := 'spawn_server'),
|
||||
|
|
|
@ -1485,7 +1485,11 @@ class Context:
|
|||
TODO: implement this using `outcome.Outcome` types?
|
||||
|
||||
'''
|
||||
return self.maybe_error or self._result
|
||||
return (
|
||||
self.maybe_error
|
||||
or
|
||||
self._result
|
||||
)
|
||||
|
||||
# @property
|
||||
def repr_outcome(
|
||||
|
@ -1520,16 +1524,28 @@ class Context:
|
|||
#
|
||||
# just the type name for now to avoid long lines
|
||||
# when tons of cancels..
|
||||
return type(merr).__name__
|
||||
return (
|
||||
str(type(merr).__name__)
|
||||
or
|
||||
repr(merr)
|
||||
)
|
||||
|
||||
# just the type name
|
||||
# else: # but wen?
|
||||
# return type(merr).__name__
|
||||
|
||||
# for all other errors show their regular output
|
||||
return str(merr)
|
||||
return (
|
||||
str(merr)
|
||||
or
|
||||
repr(merr)
|
||||
)
|
||||
|
||||
return str(self._result)
|
||||
return (
|
||||
str(self._result)
|
||||
or
|
||||
repr(self._result)
|
||||
)
|
||||
|
||||
async def started(
|
||||
self,
|
||||
|
|
|
@ -35,7 +35,10 @@ from ._portal import (
|
|||
open_portal,
|
||||
LocalPortal,
|
||||
)
|
||||
from ._state import current_actor, _runtime_vars
|
||||
from ._state import (
|
||||
current_actor,
|
||||
_runtime_vars,
|
||||
)
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -205,7 +208,11 @@ async def find_actor(
|
|||
# every call since something may change it globally (eg.
|
||||
# like in our discovery test suite)!
|
||||
from . import _root
|
||||
registry_addrs = _root._default_lo_addrs
|
||||
registry_addrs = (
|
||||
_runtime_vars['_registry_addrs']
|
||||
or
|
||||
_root._default_lo_addrs
|
||||
)
|
||||
|
||||
maybe_portals: list[
|
||||
AsyncContextManager[tuple[str, int]]
|
||||
|
|
|
@ -30,7 +30,7 @@ from typing import (
|
|||
Any,
|
||||
Callable,
|
||||
AsyncGenerator,
|
||||
Type,
|
||||
# Type,
|
||||
)
|
||||
from functools import partial
|
||||
from dataclasses import dataclass
|
||||
|
@ -41,8 +41,7 @@ from async_generator import asynccontextmanager
|
|||
|
||||
from .trionics import maybe_open_nursery
|
||||
from .devx import (
|
||||
# acquire_debug_lock,
|
||||
# pause,
|
||||
# _debug,
|
||||
maybe_wait_for_debugger,
|
||||
)
|
||||
from ._state import (
|
||||
|
@ -673,6 +672,7 @@ class Portal:
|
|||
# `Nursery.cancel_scope.cancel()`)
|
||||
except ContextCancelled as ctxc:
|
||||
scope_err = ctxc
|
||||
ctx._local_error: BaseException = scope_err
|
||||
ctxc_from_callee = ctxc
|
||||
|
||||
# XXX TODO XXX: FIX THIS debug_mode BUGGGG!!!
|
||||
|
@ -684,7 +684,7 @@ class Portal:
|
|||
# debugging the tractor-runtime itself using it's
|
||||
# own `.devx.` tooling!
|
||||
#
|
||||
# await pause()
|
||||
# await _debug.pause()
|
||||
|
||||
# CASE 2: context was cancelled by local task calling
|
||||
# `.cancel()`, we don't raise and the exit block should
|
||||
|
@ -745,18 +745,20 @@ class Portal:
|
|||
|
||||
) as caller_err:
|
||||
scope_err = caller_err
|
||||
ctx._local_error: BaseException = scope_err
|
||||
|
||||
# XXX: ALWAYS request the context to CANCEL ON any ERROR.
|
||||
# NOTE: `Context.cancel()` is conversely NEVER CALLED in
|
||||
# the `ContextCancelled` "self cancellation absorbed" case
|
||||
# handled in the block above ^^^ !!
|
||||
# await _debug.pause()
|
||||
log.cancel(
|
||||
'Context terminated due to\n\n'
|
||||
f'{caller_err}\n'
|
||||
f'.outcome => {ctx.repr_outcome()}\n'
|
||||
)
|
||||
|
||||
if debug_mode():
|
||||
# async with acquire_debug_lock(self.actor.uid):
|
||||
# async with _debug.acquire_debug_lock(self.actor.uid):
|
||||
# pass
|
||||
# TODO: factor ^ into below for non-root cases?
|
||||
was_acquired: bool = await maybe_wait_for_debugger(
|
||||
|
@ -818,6 +820,7 @@ class Portal:
|
|||
# this task didn't know until final teardown
|
||||
# / value collection.
|
||||
scope_err = berr
|
||||
ctx._local_error: BaseException = scope_err
|
||||
raise
|
||||
|
||||
# yes! this worx Bp
|
||||
|
@ -927,8 +930,10 @@ class Portal:
|
|||
# should be stored as the `Context._local_error` and
|
||||
# used in determining `Context.cancelled_caught: bool`.
|
||||
if scope_err is not None:
|
||||
ctx._local_error: BaseException = scope_err
|
||||
etype: Type[BaseException] = type(scope_err)
|
||||
# sanity, tho can remove?
|
||||
assert ctx._local_error is scope_err
|
||||
# ctx._local_error: BaseException = scope_err
|
||||
# etype: Type[BaseException] = type(scope_err)
|
||||
|
||||
# CASE 2
|
||||
if (
|
||||
|
|
|
@ -811,10 +811,10 @@ class Actor:
|
|||
name: str,
|
||||
*,
|
||||
enable_modules: list[str] = [],
|
||||
uid: str | None = None,
|
||||
loglevel: str | None = None,
|
||||
registry_addrs: list[tuple[str, int]] | None = None,
|
||||
spawn_method: str | None = None,
|
||||
uid: str|None = None,
|
||||
loglevel: str|None = None,
|
||||
registry_addrs: list[tuple[str, int]]|None = None,
|
||||
spawn_method: str|None = None,
|
||||
|
||||
# TODO: remove!
|
||||
arbiter_addr: tuple[str, int] | None = None,
|
||||
|
@ -896,6 +896,7 @@ class Actor:
|
|||
self._reg_addrs: list[tuple[str, int]] = []
|
||||
if registry_addrs:
|
||||
self.reg_addrs: list[tuple[str, int]] = registry_addrs
|
||||
_state._runtime_vars['_registry_addrs'] = registry_addrs
|
||||
|
||||
@property
|
||||
def reg_addrs(self) -> list[tuple[str, int]]:
|
||||
|
|
|
@ -33,7 +33,8 @@ _last_actor_terminated: Actor|None = None
|
|||
_runtime_vars: dict[str, Any] = {
|
||||
'_debug_mode': False,
|
||||
'_is_root': False,
|
||||
'_root_mailbox': (None, None)
|
||||
'_root_mailbox': (None, None),
|
||||
'_registry_addrs': [],
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -216,7 +216,14 @@ def _run_asyncio_task(
|
|||
try:
|
||||
result = await coro
|
||||
except BaseException as aio_err:
|
||||
log.exception('asyncio task errored')
|
||||
if isinstance(aio_err, CancelledError):
|
||||
log.runtime(
|
||||
'`asyncio` task was cancelled..\n'
|
||||
)
|
||||
else:
|
||||
log.exception(
|
||||
'`asyncio` task errored\n'
|
||||
)
|
||||
chan._aio_err = aio_err
|
||||
raise
|
||||
|
||||
|
@ -271,12 +278,22 @@ def _run_asyncio_task(
|
|||
except BaseException as terr:
|
||||
task_err = terr
|
||||
|
||||
msg: str = (
|
||||
'Infected `asyncio` task {etype_str}\n'
|
||||
f'|_{task}\n'
|
||||
)
|
||||
if isinstance(terr, CancelledError):
|
||||
log.cancel(f'`asyncio` task cancelled: {task.get_name()}')
|
||||
log.cancel(
|
||||
msg.format(etype_str='cancelled')
|
||||
)
|
||||
else:
|
||||
log.exception(f'`asyncio` task: {task.get_name()} errored')
|
||||
log.exception(
|
||||
msg.format(etype_str='cancelled')
|
||||
)
|
||||
|
||||
assert type(terr) is type(aio_err), 'Asyncio task error mismatch?'
|
||||
assert type(terr) is type(aio_err), (
|
||||
'`asyncio` task error mismatch?!?'
|
||||
)
|
||||
|
||||
if aio_err is not None:
|
||||
# XXX: uhh is this true?
|
||||
|
@ -289,19 +306,23 @@ def _run_asyncio_task(
|
|||
# We might want to change this in the future though.
|
||||
from_aio.close()
|
||||
|
||||
if type(aio_err) is CancelledError:
|
||||
log.cancel("infected task was cancelled")
|
||||
if task_err is None:
|
||||
assert aio_err
|
||||
aio_err.with_traceback(aio_err.__traceback__)
|
||||
# log.error(
|
||||
# 'infected task errorred'
|
||||
# )
|
||||
|
||||
# TODO: show that the cancellation originated
|
||||
# from the ``trio`` side? right?
|
||||
# elif type(aio_err) is CancelledError:
|
||||
# log.cancel(
|
||||
# 'infected task was cancelled'
|
||||
# )
|
||||
|
||||
# if cancel_scope.cancelled:
|
||||
# raise aio_err from err
|
||||
|
||||
elif task_err is None:
|
||||
assert aio_err
|
||||
aio_err.with_traceback(aio_err.__traceback__)
|
||||
log.error('infected task errorred')
|
||||
|
||||
# XXX: alway cancel the scope on error
|
||||
# in case the trio task is blocking
|
||||
# on a checkpoint.
|
||||
|
|
Loading…
Reference in New Issue