forked from goodboy/tractor
Create runtime variables
parent
ed96672136
commit
90499c19d7
|
@ -3,10 +3,15 @@ Per process state
|
||||||
"""
|
"""
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from collections import Mapping
|
from collections import Mapping
|
||||||
|
import multiprocessing as mp
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
_current_actor: Optional['Actor'] = None # type: ignore
|
_current_actor: Optional['Actor'] = None # type: ignore
|
||||||
|
_runtime_vars = {
|
||||||
|
'_debug_mode': False,
|
||||||
|
'_is_root': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def current_actor() -> 'Actor': # type: ignore
|
def current_actor() -> 'Actor': # type: ignore
|
||||||
|
@ -36,3 +41,20 @@ class ActorContextInfo(Mapping):
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# no local actor/task context initialized yet
|
# no local actor/task context initialized yet
|
||||||
return f'no {key} context'
|
return f'no {key} context'
|
||||||
|
|
||||||
|
|
||||||
|
def is_main_process() -> bool:
|
||||||
|
"""Bool determining if this actor is running in the top-most process.
|
||||||
|
"""
|
||||||
|
return mp.current_process().name == 'MainProcess'
|
||||||
|
|
||||||
|
|
||||||
|
def debug_mode() -> bool:
|
||||||
|
"""Bool determining if "debug mode" is on which enables
|
||||||
|
remote subactor pdb entry on crashes.
|
||||||
|
"""
|
||||||
|
return _runtime_vars['_debug_mode']
|
||||||
|
|
||||||
|
|
||||||
|
def is_root_process() -> bool:
|
||||||
|
return _runtime_vars['_is_root']
|
||||||
|
|
Loading…
Reference in New Issue