From 3201437f4e6eb47370cc4422c6dbc0989e9a1133 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 29 Jun 2025 15:47:42 -0400 Subject: [PATCH] More `.ipc.Channel`-repr related tweaks - only generate a repr in `.from_addr()` when log level is >= 'runtime'. |_ add a todo about supporting this optimization more generally on our adapter. - fix `Channel.pformat()` to show unknown peer field line fmt correctly. - add a `Channel.maddr: str` which just delegates directly to the `._transport` like other pass-thru property fields. --- tractor/ipc/_chan.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tractor/ipc/_chan.py b/tractor/ipc/_chan.py index 478b4024..0f36b056 100644 --- a/tractor/ipc/_chan.py +++ b/tractor/ipc/_chan.py @@ -171,11 +171,23 @@ class Channel: ) assert transport.raddr == addr chan = Channel(transport=transport) - log.runtime( - f'Connected channel IPC transport\n' - f'[>\n' - f' |_{chan}\n' - ) + + # ?TODO, compact this into adapter level-methods? + # -[ ] would avoid extra repr-calcs if level not active? + # |_ how would the `calc_if_level` look though? func? + if log.at_least_level('runtime'): + from tractor.devx import ( + pformat as _pformat, + ) + chan_repr: str = _pformat.nest_from_op( + input_op='[>', + text=chan.pformat(), + nest_indent=1, + ) + log.runtime( + f'Connected channel IPC transport\n' + f'{chan_repr}' + ) return chan @cm @@ -218,7 +230,7 @@ class Channel: if privates else '' ) + ( # peer-actor (processs) section f' |_peer: {self.aid.reprol()!r}\n' - if self.aid else '' + if self.aid else ' |_peer: \n' ) + ( f' |_msgstream: {tpt_name}\n' f' maddr: {tpt.maddr!r}\n' @@ -259,6 +271,10 @@ class Channel: def raddr(self) -> Address|None: return self._transport.raddr if self._transport else None + @property + def maddr(self) -> str: + return self._transport.maddr if self._transport else '' + # TODO: something like, # `pdbp.hideframe_on(errors=[MsgTypeError])` # instead of the `try/except` hack we have rn..