From 897ab79946dbe122eaaf82ed91f3fc697410a12a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 27 Apr 2021 11:07:53 -0400 Subject: [PATCH] Add a no runtime error --- tractor/_exceptions.py | 4 ++++ tractor/_state.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tractor/_exceptions.py b/tractor/_exceptions.py index 63e0d09..6137590 100644 --- a/tractor/_exceptions.py +++ b/tractor/_exceptions.py @@ -46,6 +46,10 @@ class ModuleNotExposed(ModuleNotFoundError): "The requested module is not exposed for RPC" +class NoRuntime(RuntimeError): + "The root actor has not been initialized yet" + + def pack_error(exc: BaseException) -> Dict[str, Any]: """Create an "error message" for tranmission over a channel (aka the wire). diff --git a/tractor/_state.py b/tractor/_state.py index 37fdafa..1d5e2f3 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -7,6 +7,9 @@ import multiprocessing as mp import trio +from ._exceptions import NoRuntime + + _current_actor: Optional['Actor'] = None # type: ignore # noqa _runtime_vars: Dict[str, Any] = { '_debug_mode': False, @@ -19,7 +22,7 @@ def current_actor(err_on_no_runtime: bool = True) -> 'Actor': # type: ignore # """Get the process-local actor instance. """ if _current_actor is None and err_on_no_runtime: - raise RuntimeError("No local actor has been initialized yet") + raise NoRuntime("No local actor has been initialized yet") return _current_actor