Formally add `nest_from_op()` XD
Moving it from where i (oddly) first wrote it up in `._entry` to a more proper place with its pals in `.devx.pformat` ;prepl_fixture
							parent
							
								
									1eb0d785a8
								
							
						
					
					
						commit
						7c09972c7f
					
				| 
						 | 
					@ -22,7 +22,6 @@ from __future__ import annotations
 | 
				
			||||||
from functools import partial
 | 
					from functools import partial
 | 
				
			||||||
import multiprocessing as mp
 | 
					import multiprocessing as mp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import textwrap
 | 
					 | 
				
			||||||
from typing import (
 | 
					from typing import (
 | 
				
			||||||
    Any,
 | 
					    Any,
 | 
				
			||||||
    TYPE_CHECKING,
 | 
					    TYPE_CHECKING,
 | 
				
			||||||
| 
						 | 
					@ -35,7 +34,10 @@ from .log import (
 | 
				
			||||||
    get_logger,
 | 
					    get_logger,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from . import _state
 | 
					from . import _state
 | 
				
			||||||
from .devx import _debug
 | 
					from .devx import (
 | 
				
			||||||
 | 
					    _debug,
 | 
				
			||||||
 | 
					    pformat,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
from .to_asyncio import run_as_asyncio_guest
 | 
					from .to_asyncio import run_as_asyncio_guest
 | 
				
			||||||
from ._addr import UnwrappedAddress
 | 
					from ._addr import UnwrappedAddress
 | 
				
			||||||
from ._runtime import (
 | 
					from ._runtime import (
 | 
				
			||||||
| 
						 | 
					@ -103,107 +105,6 @@ def _mp_main(
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO: move this func to some kinda `.devx._conc_lang.py` eventually
 | 
					 | 
				
			||||||
# as we work out our multi-domain state-flow-syntax!
 | 
					 | 
				
			||||||
def nest_from_op(
 | 
					 | 
				
			||||||
    input_op: str,
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # ?TODO? an idea for a syntax to the state of concurrent systems
 | 
					 | 
				
			||||||
    # as a "3-domain" (execution, scope, storage) model and using
 | 
					 | 
				
			||||||
    # a minimal ascii/utf-8 operator-set.
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # try not to take any of this seriously yet XD
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # > is a "play operator" indicating (CPU bound)
 | 
					 | 
				
			||||||
    #   exec/work/ops required at the "lowest level computing"
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # execution primititves (tasks, threads, actors..) denote their
 | 
					 | 
				
			||||||
    # lifetime with '(' and ')' since parentheses normally are used
 | 
					 | 
				
			||||||
    # in many langs to denote function calls.
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # starting = (
 | 
					 | 
				
			||||||
    # >(  opening/starting; beginning of the thread-of-exec (toe?)
 | 
					 | 
				
			||||||
    # (>  opened/started,  (finished spawning toe)
 | 
					 | 
				
			||||||
    # |_<Task: blah blah..>  repr of toe, in py these look like <objs>
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # >) closing/exiting/stopping,
 | 
					 | 
				
			||||||
    # )> closed/exited/stopped,
 | 
					 | 
				
			||||||
    # |_<Task: blah blah..>
 | 
					 | 
				
			||||||
    #   [OR <), )< ?? ]
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # ending = )
 | 
					 | 
				
			||||||
    # >c) cancelling to close/exit
 | 
					 | 
				
			||||||
    # c)> cancelled (caused close), OR?
 | 
					 | 
				
			||||||
    #  |_<Actor: ..>
 | 
					 | 
				
			||||||
    #   OR maybe "<c)" which better indicates the cancel being
 | 
					 | 
				
			||||||
    #   "delivered/returned" / returned" to LHS?
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # >x)  erroring to eventuall exit
 | 
					 | 
				
			||||||
    # x)>  errored and terminated
 | 
					 | 
				
			||||||
    #  |_<Actor: ...>
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # scopes: supers/nurseries, IPC-ctxs, sessions, perms, etc.
 | 
					 | 
				
			||||||
    # >{  opening
 | 
					 | 
				
			||||||
    # {>  opened
 | 
					 | 
				
			||||||
    # }>  closed
 | 
					 | 
				
			||||||
    # >}  closing
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # storage: like queues, shm-buffers, files, etc..
 | 
					 | 
				
			||||||
    # >[  opening
 | 
					 | 
				
			||||||
    # [>  opened
 | 
					 | 
				
			||||||
    #  |_<FileObj: ..>
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # >]  closing
 | 
					 | 
				
			||||||
    # ]>  closed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # IPC ops: channels, transports, msging
 | 
					 | 
				
			||||||
    # =>  req msg
 | 
					 | 
				
			||||||
    # <=  resp msg
 | 
					 | 
				
			||||||
    # <=> 2-way streaming (of msgs)
 | 
					 | 
				
			||||||
    # <-  recv 1 msg
 | 
					 | 
				
			||||||
    # ->  send 1 msg
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # TODO: still not sure on R/L-HS approach..?
 | 
					 | 
				
			||||||
    # =>(  send-req to exec start (task, actor, thread..)
 | 
					 | 
				
			||||||
    # (<=  recv-req to ^
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # (<=  recv-req ^
 | 
					 | 
				
			||||||
    # <=(  recv-resp opened remote exec primitive
 | 
					 | 
				
			||||||
    # <=)  recv-resp closed
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # )<=c req to stop due to cancel
 | 
					 | 
				
			||||||
    # c=>) req to stop due to cancel
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # =>{  recv-req to open
 | 
					 | 
				
			||||||
    # <={  send-status that it closed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    tree_str: str,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # NOTE: so move back-from-the-left of the `input_op` by
 | 
					 | 
				
			||||||
    # this amount.
 | 
					 | 
				
			||||||
    back_from_op: int = 0,
 | 
					 | 
				
			||||||
) -> str:
 | 
					 | 
				
			||||||
    '''
 | 
					 | 
				
			||||||
    Depth-increment the input (presumably hierarchy/supervision)
 | 
					 | 
				
			||||||
    input "tree string" below the provided `input_op` execution
 | 
					 | 
				
			||||||
    operator, so injecting a `"\n|_{input_op}\n"`and indenting the
 | 
					 | 
				
			||||||
    `tree_str` to nest content aligned with the ops last char.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    '''
 | 
					 | 
				
			||||||
    return (
 | 
					 | 
				
			||||||
        f'{input_op}\n'
 | 
					 | 
				
			||||||
        +
 | 
					 | 
				
			||||||
        textwrap.indent(
 | 
					 | 
				
			||||||
            tree_str,
 | 
					 | 
				
			||||||
            prefix=(
 | 
					 | 
				
			||||||
                len(input_op)
 | 
					 | 
				
			||||||
                -
 | 
					 | 
				
			||||||
                (back_from_op + 1)
 | 
					 | 
				
			||||||
            ) * ' ',
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def _trio_main(
 | 
					def _trio_main(
 | 
				
			||||||
    actor: Actor,
 | 
					    actor: Actor,
 | 
				
			||||||
    *,
 | 
					    *,
 | 
				
			||||||
| 
						 | 
					@ -236,7 +137,7 @@ def _trio_main(
 | 
				
			||||||
        log.info(
 | 
					        log.info(
 | 
				
			||||||
            'Starting new `trio` subactor:\n'
 | 
					            'Starting new `trio` subactor:\n'
 | 
				
			||||||
            +
 | 
					            +
 | 
				
			||||||
            nest_from_op(
 | 
					            pformat.nest_from_op(
 | 
				
			||||||
                input_op='>(',  # see syntax ideas above
 | 
					                input_op='>(',  # see syntax ideas above
 | 
				
			||||||
                tree_str=actor_info,
 | 
					                tree_str=actor_info,
 | 
				
			||||||
                back_from_op=2,  # since "complete"
 | 
					                back_from_op=2,  # since "complete"
 | 
				
			||||||
| 
						 | 
					@ -246,7 +147,7 @@ def _trio_main(
 | 
				
			||||||
    exit_status: str = (
 | 
					    exit_status: str = (
 | 
				
			||||||
        'Subactor exited\n'
 | 
					        'Subactor exited\n'
 | 
				
			||||||
        +
 | 
					        +
 | 
				
			||||||
        nest_from_op(
 | 
					        pformat.nest_from_op(
 | 
				
			||||||
            input_op=')>',  # like a "closed-to-play"-icon from super perspective
 | 
					            input_op=')>',  # like a "closed-to-play"-icon from super perspective
 | 
				
			||||||
            tree_str=actor_info,
 | 
					            tree_str=actor_info,
 | 
				
			||||||
            back_from_op=1,
 | 
					            back_from_op=1,
 | 
				
			||||||
| 
						 | 
					@ -264,7 +165,7 @@ def _trio_main(
 | 
				
			||||||
        exit_status: str = (
 | 
					        exit_status: str = (
 | 
				
			||||||
            'Actor received KBI (aka an OS-cancel)\n'
 | 
					            'Actor received KBI (aka an OS-cancel)\n'
 | 
				
			||||||
            +
 | 
					            +
 | 
				
			||||||
            nest_from_op(
 | 
					            pformat.nest_from_op(
 | 
				
			||||||
                input_op='c)>',  # closed due to cancel (see above)
 | 
					                input_op='c)>',  # closed due to cancel (see above)
 | 
				
			||||||
                tree_str=actor_info,
 | 
					                tree_str=actor_info,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
| 
						 | 
					@ -274,7 +175,7 @@ def _trio_main(
 | 
				
			||||||
        exit_status: str = (
 | 
					        exit_status: str = (
 | 
				
			||||||
            'Main actor task exited due to crash?\n'
 | 
					            'Main actor task exited due to crash?\n'
 | 
				
			||||||
            +
 | 
					            +
 | 
				
			||||||
            nest_from_op(
 | 
					            pformat.nest_from_op(
 | 
				
			||||||
                input_op='x)>',  # closed by error
 | 
					                input_op='x)>',  # closed by error
 | 
				
			||||||
                tree_str=actor_info,
 | 
					                tree_str=actor_info,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -247,3 +247,104 @@ def pformat_cs(
 | 
				
			||||||
        +
 | 
					        +
 | 
				
			||||||
        fields
 | 
					        fields
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# TODO: move this func to some kinda `.devx.pformat.py` eventually
 | 
				
			||||||
 | 
					# as we work out our multi-domain state-flow-syntax!
 | 
				
			||||||
 | 
					def nest_from_op(
 | 
				
			||||||
 | 
					    input_op: str,
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # ?TODO? an idea for a syntax to the state of concurrent systems
 | 
				
			||||||
 | 
					    # as a "3-domain" (execution, scope, storage) model and using
 | 
				
			||||||
 | 
					    # a minimal ascii/utf-8 operator-set.
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # try not to take any of this seriously yet XD
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # > is a "play operator" indicating (CPU bound)
 | 
				
			||||||
 | 
					    #   exec/work/ops required at the "lowest level computing"
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # execution primititves (tasks, threads, actors..) denote their
 | 
				
			||||||
 | 
					    # lifetime with '(' and ')' since parentheses normally are used
 | 
				
			||||||
 | 
					    # in many langs to denote function calls.
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # starting = (
 | 
				
			||||||
 | 
					    # >(  opening/starting; beginning of the thread-of-exec (toe?)
 | 
				
			||||||
 | 
					    # (>  opened/started,  (finished spawning toe)
 | 
				
			||||||
 | 
					    # |_<Task: blah blah..>  repr of toe, in py these look like <objs>
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # >) closing/exiting/stopping,
 | 
				
			||||||
 | 
					    # )> closed/exited/stopped,
 | 
				
			||||||
 | 
					    # |_<Task: blah blah..>
 | 
				
			||||||
 | 
					    #   [OR <), )< ?? ]
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # ending = )
 | 
				
			||||||
 | 
					    # >c) cancelling to close/exit
 | 
				
			||||||
 | 
					    # c)> cancelled (caused close), OR?
 | 
				
			||||||
 | 
					    #  |_<Actor: ..>
 | 
				
			||||||
 | 
					    #   OR maybe "<c)" which better indicates the cancel being
 | 
				
			||||||
 | 
					    #   "delivered/returned" / returned" to LHS?
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # >x)  erroring to eventuall exit
 | 
				
			||||||
 | 
					    # x)>  errored and terminated
 | 
				
			||||||
 | 
					    #  |_<Actor: ...>
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # scopes: supers/nurseries, IPC-ctxs, sessions, perms, etc.
 | 
				
			||||||
 | 
					    # >{  opening
 | 
				
			||||||
 | 
					    # {>  opened
 | 
				
			||||||
 | 
					    # }>  closed
 | 
				
			||||||
 | 
					    # >}  closing
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # storage: like queues, shm-buffers, files, etc..
 | 
				
			||||||
 | 
					    # >[  opening
 | 
				
			||||||
 | 
					    # [>  opened
 | 
				
			||||||
 | 
					    #  |_<FileObj: ..>
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # >]  closing
 | 
				
			||||||
 | 
					    # ]>  closed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # IPC ops: channels, transports, msging
 | 
				
			||||||
 | 
					    # =>  req msg
 | 
				
			||||||
 | 
					    # <=  resp msg
 | 
				
			||||||
 | 
					    # <=> 2-way streaming (of msgs)
 | 
				
			||||||
 | 
					    # <-  recv 1 msg
 | 
				
			||||||
 | 
					    # ->  send 1 msg
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # TODO: still not sure on R/L-HS approach..?
 | 
				
			||||||
 | 
					    # =>(  send-req to exec start (task, actor, thread..)
 | 
				
			||||||
 | 
					    # (<=  recv-req to ^
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # (<=  recv-req ^
 | 
				
			||||||
 | 
					    # <=(  recv-resp opened remote exec primitive
 | 
				
			||||||
 | 
					    # <=)  recv-resp closed
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # )<=c req to stop due to cancel
 | 
				
			||||||
 | 
					    # c=>) req to stop due to cancel
 | 
				
			||||||
 | 
					    #
 | 
				
			||||||
 | 
					    # =>{  recv-req to open
 | 
				
			||||||
 | 
					    # <={  send-status that it closed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    tree_str: str,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # NOTE: so move back-from-the-left of the `input_op` by
 | 
				
			||||||
 | 
					    # this amount.
 | 
				
			||||||
 | 
					    back_from_op: int = 0,
 | 
				
			||||||
 | 
					) -> str:
 | 
				
			||||||
 | 
					    '''
 | 
				
			||||||
 | 
					    Depth-increment the input (presumably hierarchy/supervision)
 | 
				
			||||||
 | 
					    input "tree string" below the provided `input_op` execution
 | 
				
			||||||
 | 
					    operator, so injecting a `"\n|_{input_op}\n"`and indenting the
 | 
				
			||||||
 | 
					    `tree_str` to nest content aligned with the ops last char.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    '''
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        f'{input_op}\n'
 | 
				
			||||||
 | 
					        +
 | 
				
			||||||
 | 
					        textwrap.indent(
 | 
				
			||||||
 | 
					            tree_str,
 | 
				
			||||||
 | 
					            prefix=(
 | 
				
			||||||
 | 
					                len(input_op)
 | 
				
			||||||
 | 
					                -
 | 
				
			||||||
 | 
					                (back_from_op + 1)
 | 
				
			||||||
 | 
					            ) * ' ',
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue