Config debug mode log level *after* initial setup

agpl
Tyler Goodlet 2021-11-22 13:28:30 -05:00
parent 205e254072
commit 72eef2a4a1
1 changed files with 33 additions and 31 deletions

View File

@ -1,6 +1,7 @@
""" '''
Root actor runtime ignition(s). Root actor runtime ignition(s).
"""
'''
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from functools import partial from functools import partial
import importlib import importlib
@ -81,30 +82,6 @@ async def open_root_actor(
if start_method is not None: if start_method is not None:
_spawn.try_set_start_method(start_method) _spawn.try_set_start_method(start_method)
if debug_mode and _spawn._spawn_method == 'trio':
_state._runtime_vars['_debug_mode'] = True
# expose internal debug module to every actor allowing
# for use of ``await tractor.breakpoint()``
enable_modules.append('tractor._debug')
# if debug mode get's enabled *at least* use that level of
# logging for some informative console prompts.
if loglevel is None:
if (
logging.getLevelName(
# lul, need the upper case for the -> int map?
# sweet "dynamic function behaviour" stdlib...
log.get_loglevel().upper()
) > logging.getLevelName('PDB')
):
loglevel = 'PDB'
elif debug_mode:
raise RuntimeError(
"Debug mode is only supported for the `trio` backend!"
)
arbiter_addr = (host, port) = arbiter_addr or ( arbiter_addr = (host, port) = arbiter_addr or (
_default_arbiter_host, _default_arbiter_host,
_default_arbiter_port, _default_arbiter_port,
@ -115,6 +92,29 @@ async def open_root_actor(
log._default_loglevel = loglevel log._default_loglevel = loglevel
log.get_console_log(loglevel) log.get_console_log(loglevel)
if debug_mode and _spawn._spawn_method == 'trio':
_state._runtime_vars['_debug_mode'] = True
# expose internal debug module to every actor allowing
# for use of ``await tractor.breakpoint()``
enable_modules.append('tractor._debug')
# if debug mode get's enabled *at least* use that level of
# logging for some informative console prompts.
if (
logging.getLevelName(
# lul, need the upper case for the -> int map?
# sweet "dynamic function behaviour" stdlib...
log.get_loglevel().upper()
) > logging.getLevelName('PDB')
):
loglevel = 'PDB'
elif debug_mode:
raise RuntimeError(
"Debug mode is only supported for the `trio` backend!"
)
# make a temporary connection to see if an arbiter exists # make a temporary connection to see if an arbiter exists
arbiter_found = False arbiter_found = False
@ -248,18 +248,20 @@ def run(
def run_daemon( def run_daemon(
rpc_module_paths: List[str], enable_modules: list[str],
**kwargs **kwargs
) -> None: ) -> None:
"""Spawn daemon actor which will respond to RPC. '''
Spawn daemon actor which will respond to RPC.
This is a convenience wrapper around This is a convenience wrapper around
``tractor.run(trio.sleep(float('inf')))`` such that the first actor spawned ``tractor.run(trio.sleep(float('inf')))`` such that the first actor spawned
is meant to run forever responding to RPC requests. is meant to run forever responding to RPC requests.
"""
kwargs['rpc_module_paths'] = list(rpc_module_paths)
for path in rpc_module_paths: '''
kwargs['enable_modules'] = list(enable_modules)
for path in enable_modules:
importlib.import_module(path) importlib.import_module(path)
return run(partial(trio.sleep, float('inf')), **kwargs) return run(partial(trio.sleep, float('inf')), **kwargs)