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
and (reason := 'stream was already closed')
)
or (ctx.cancel_acked
and (reason := 'ctx cancelled other side')
or (ctx._cancelled_caught
and (reason := 'ctx caught a cancel')
)
or (ctx._cancel_called
and (reason := 'ctx called `.cancel()`')

View File

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

View File

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

View File

@ -18,18 +18,12 @@
Per process state
"""
from __future__ import annotations
from typing import (
Optional,
Any,
TYPE_CHECKING,
)
if TYPE_CHECKING:
from ._runtime import Actor
_current_actor: Actor|None = None # type: ignore # noqa
_last_actor_terminated: Actor|None = None
_current_actor: Optional['Actor'] = None # type: ignore # noqa
_runtime_vars: dict[str, Any] = {
'_debug_mode': False,
'_is_root': False,
@ -37,49 +31,14 @@ _runtime_vars: dict[str, Any] = {
}
def last_actor() -> Actor|None:
'''
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:
def current_actor(err_on_no_runtime: bool = True) -> 'Actor': # type: ignore # noqa
'''
Get the process-local actor instance.
'''
if (
err_on_no_runtime
and _current_actor is None
):
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)
from ._exceptions import NoRuntime
if _current_actor is None and err_on_no_runtime:
raise NoRuntime("No local actor has been initialized yet")
return _current_actor

View File

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