From f54c415060f711ed5414d4e791a06834f8c17518 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 13 Apr 2023 15:16:39 -0400 Subject: [PATCH] Move `NoRuntime` import inside `current_actor()` to avoid cycle --- tractor/_state.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tractor/_state.py b/tractor/_state.py index 28fa16e..f94c3eb 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -23,11 +23,6 @@ from typing import ( Any, ) -import trio - -from ._exceptions import NoRuntime - - _current_actor: Optional['Actor'] = None # type: ignore # noqa _runtime_vars: dict[str, Any] = { '_debug_mode': False, @@ -37,8 +32,11 @@ _runtime_vars: dict[str, Any] = { def current_actor(err_on_no_runtime: bool = True) -> 'Actor': # type: ignore # noqa - """Get the process-local actor instance. - """ + ''' + Get the process-local actor instance. + + ''' + from ._exceptions import NoRuntime if _current_actor is None and err_on_no_runtime: raise NoRuntime("No local actor has been initialized yet") @@ -46,16 +44,20 @@ def current_actor(err_on_no_runtime: bool = True) -> 'Actor': # type: ignore # def is_main_process() -> bool: - """Bool determining if this actor is running in the top-most process. - """ + ''' + Bool determining if this actor is running in the top-most process. + + ''' import multiprocessing as mp return mp.current_process().name == 'MainProcess' def debug_mode() -> bool: - """Bool determining if "debug mode" is on which enables + ''' + Bool determining if "debug mode" is on which enables remote subactor pdb entry on crashes. - """ + + ''' return bool(_runtime_vars['_debug_mode'])