Compare commits

..

No commits in common. "4c3c3e4b565637cd4ee9213501c0bf6a55a3b2dd" and "c025761f15bb09c308ffc44f4776e71a4d2a60f4" have entirely different histories.

5 changed files with 13 additions and 59 deletions

View File

@ -196,8 +196,8 @@ async def _drain_to_final_msg(
(ctx._stream.closed (ctx._stream.closed
and (reason := 'stream was already closed') and (reason := 'stream was already closed')
) )
or (ctx.cancel_acked or (ctx._cancelled_caught
and (reason := 'ctx cancelled other side') and (reason := 'ctx caught a cancel')
) )
or (ctx._cancel_called or (ctx._cancel_called
and (reason := 'ctx called `.cancel()`') and (reason := 'ctx called `.cancel()`')

View File

@ -348,7 +348,6 @@ async def open_root_actor(
await actor.cancel(None) # self cancel await actor.cancel(None) # self cancel
finally: finally:
_state._current_actor = None _state._current_actor = None
_state._last_actor_terminated = actor
# restore built-in `breakpoint()` hook state # restore built-in `breakpoint()` hook state
sys.breakpointhook = builtin_bp_handler sys.breakpointhook = builtin_bp_handler

View File

@ -1752,8 +1752,8 @@ class Actor:
self, self,
cid: str, cid: str,
parent_chan: Channel, parent_chan: Channel,
requesting_uid: tuple[str, str]|None,
requesting_uid: tuple[str, str]|None = None,
ipc_msg: dict|None|bool = False, ipc_msg: dict|None|bool = False,
) -> bool: ) -> bool:
@ -2352,7 +2352,6 @@ async def process_messages(
await actor._cancel_task( await actor._cancel_task(
cid, cid,
channel, channel,
requesting_uid=channel.uid,
ipc_msg=msg, ipc_msg=msg,
) )

View File

@ -18,18 +18,12 @@
Per process state Per process state
""" """
from __future__ import annotations
from typing import ( from typing import (
Optional,
Any, Any,
TYPE_CHECKING,
) )
if TYPE_CHECKING: _current_actor: Optional['Actor'] = None # type: ignore # noqa
from ._runtime import Actor
_current_actor: Actor|None = None # type: ignore # noqa
_last_actor_terminated: Actor|None = None
_runtime_vars: dict[str, Any] = { _runtime_vars: dict[str, Any] = {
'_debug_mode': False, '_debug_mode': False,
'_is_root': False, '_is_root': False,
@ -37,49 +31,14 @@ _runtime_vars: dict[str, Any] = {
} }
def last_actor() -> Actor|None: def current_actor(err_on_no_runtime: bool = True) -> 'Actor': # type: ignore # noqa
'''
Try to return last active `Actor` singleton
for this process.
For case where runtime already exited but someone is asking
about the "last" actor probably to get its `.uid: tuple`.
'''
return _last_actor_terminated
def current_actor(
err_on_no_runtime: bool = True,
) -> Actor:
''' '''
Get the process-local actor instance. Get the process-local actor instance.
''' '''
if ( from ._exceptions import NoRuntime
err_on_no_runtime if _current_actor is None and err_on_no_runtime:
and _current_actor is None raise NoRuntime("No local actor has been initialized yet")
):
msg: str = 'No local actor has been initialized yet'
from ._exceptions import NoRuntime
if last := last_actor():
msg += (
f'Apparently the lact active actor was\n'
f'|_{last}\n'
f'|_{last.uid}\n'
)
# no actor runtime has (as of yet) ever been started for
# this process.
else:
msg += (
'No last actor found?\n'
'Did you forget to open one of:\n\n'
'- `tractor.open_root_actor()`\n'
'- `tractor.open_nursery()`\n'
)
raise NoRuntime(msg)
return _current_actor return _current_actor

View File

@ -533,15 +533,12 @@ async def open_nursery(
''' '''
implicit_runtime: bool = False implicit_runtime: bool = False
actor: Actor = current_actor(
err_on_no_runtime=False actor = current_actor(err_on_no_runtime=False)
)
try: try:
if ( if actor is None and is_main_process():
actor is None
and is_main_process()
):
# if we are the parent process start the # if we are the parent process start the
# actor runtime implicitly # actor runtime implicitly
log.info("Starting actor runtime!") log.info("Starting actor runtime!")