Move `_debug.pformat_cs()` into `devx.pformat`
parent
05b143d9ef
commit
4d528b76a0
|
@ -73,7 +73,10 @@ from tractor._state import (
|
||||||
debug_mode,
|
debug_mode,
|
||||||
current_ipc_ctx,
|
current_ipc_ctx,
|
||||||
)
|
)
|
||||||
# from .pformat import pformat_caller_frame
|
from .pformat import (
|
||||||
|
# pformat_caller_frame,
|
||||||
|
pformat_cs,
|
||||||
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from tractor._ipc import Channel
|
from tractor._ipc import Channel
|
||||||
|
@ -868,20 +871,6 @@ def apply_debug_pldec() -> _codec.MsgCodec:
|
||||||
f'{orig_pldec}\n'
|
f'{orig_pldec}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: add this formatter to `.devx.pformat()`!
|
|
||||||
def pformat_cs(
|
|
||||||
cs: CancelScope,
|
|
||||||
var_name: str = 'cs',
|
|
||||||
) -> str:
|
|
||||||
return (
|
|
||||||
f'{var_name}: {cs}\n'
|
|
||||||
f'{var_name}.cancel_called = {cs.cancel_called}\n'
|
|
||||||
f'{var_name}.cancelled_caught = {cs.cancelled_caught}\n'
|
|
||||||
f'{var_name}._cancel_status = {cs._cancel_status}\n'
|
|
||||||
f'{var_name}.shield = {cs.shield}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def request_root_stdio_lock(
|
async def request_root_stdio_lock(
|
||||||
actor_uid: tuple[str, str],
|
actor_uid: tuple[str, str],
|
||||||
task_uid: tuple[str, int],
|
task_uid: tuple[str, int],
|
||||||
|
|
|
@ -22,6 +22,8 @@ Mostly handy for logging and exception message content.
|
||||||
import textwrap
|
import textwrap
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from trio import CancelScope
|
||||||
|
|
||||||
|
|
||||||
def add_div(
|
def add_div(
|
||||||
message: str,
|
message: str,
|
||||||
|
@ -133,3 +135,34 @@ def pformat_caller_frame(
|
||||||
indent='',
|
indent='',
|
||||||
)
|
)
|
||||||
return tb_str
|
return tb_str
|
||||||
|
|
||||||
|
|
||||||
|
def pformat_cs(
|
||||||
|
cs: CancelScope,
|
||||||
|
var_name: str = 'cs',
|
||||||
|
field_prefix: str = ' |_',
|
||||||
|
) -> str:
|
||||||
|
'''
|
||||||
|
Pretty format info about a `trio.CancelScope` including most
|
||||||
|
of its public state and `._cancel_status`.
|
||||||
|
|
||||||
|
The output can be modified to show a "var name" for the
|
||||||
|
instance as a field prefix, just a simple str before each
|
||||||
|
line more or less.
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
fields: str = textwrap.indent(
|
||||||
|
(
|
||||||
|
f'cancel_called = {cs.cancel_called}\n'
|
||||||
|
f'cancelled_caught = {cs.cancelled_caught}\n'
|
||||||
|
f'_cancel_status = {cs._cancel_status}\n'
|
||||||
|
f'shield = {cs.shield}\n'
|
||||||
|
),
|
||||||
|
prefix=field_prefix,
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
f'{var_name}: {cs}\n'
|
||||||
|
+
|
||||||
|
fields
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue