Skip to content

Commit f8dbefc

Browse files
committed
code: wait on tmux channel for no-tty cli operation
Signed-off-by: Christian Hopps <[email protected]>
1 parent 45a5670 commit f8dbefc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

munet/cli.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ async def remote_cli(unet, prompt, title, background):
756756
unet.cli_sockpath = sockpath
757757
logging.info("server created on :\n%s\n", sockpath)
758758

759+
wait_tmux = bool(os.getenv("TMUX", "")) and not sys.stdin.isatty()
760+
759761
# Open a new window with a new CLI
760762
python_path = await unet.async_get_exec_path(["python3", "python"])
761763
us = os.path.realpath(__file__)
@@ -765,7 +767,25 @@ async def remote_cli(unet, prompt, title, background):
765767
if prompt:
766768
cmd += f" --prompt='{prompt}'"
767769
cmd += " " + unet.cli_sockpath
768-
unet.run_in_window(cmd, title=title, background=False)
770+
771+
channel = None
772+
if wait_tmux:
773+
from .base import Commander # pylint: disable=import-outside-toplevel
774+
775+
channel = "{}-{}".format(os.getpid(), Commander.tmux_wait_gen)
776+
logger.info("XXX channel is %s", channel)
777+
# If we don't have a tty to pause on pause for tmux windows to exit
778+
if channel is not None:
779+
Commander.tmux_wait_gen += 1
780+
781+
unet.run_in_window(cmd, title=title, background=False, wait_for=channel)
782+
783+
if wait_tmux and channel:
784+
from .base import commander # pylint: disable=import-outside-toplevel
785+
786+
await commander.async_cmd_raises(
787+
[commander.get_exec_path("tmux"), "wait", channel]
788+
)
769789
except Exception as error:
770790
logging.error("cli server: unexpected exception: %s", error)
771791

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "munet"
3-
version = "0.14.12"
3+
version = "0.14.13"
44
description = "A package to facilitate network simulations"
55
authors = ["Christian Hopps <[email protected]>"]
66
license = "GPL-2.0-or-later"

0 commit comments

Comments
 (0)