From cf662c90a89000cc05c1f8bf9f0473d0847a84fe Mon Sep 17 00:00:00 2001 From: Tobias Dideriksen Date: Mon, 22 Jun 2026 11:26:37 +0200 Subject: [PATCH] Fix asyncio.get_event_loop() RuntimeError on Python 3.12+ Python 3.12+ no longer implicitly creates an event loop when get_event_loop() is called with none set, raising RuntimeError instead. Ensure an event loop exists before handing control to iterm2. Co-Authored-By: Claude Sonnet 4.6 --- src/i2cssh/lib.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/i2cssh/lib.py b/src/i2cssh/lib.py index 50378ba..9b4702f 100755 --- a/src/i2cssh/lib.py +++ b/src/i2cssh/lib.py @@ -299,6 +299,12 @@ def app(hosts_or_cluster, *_args, **cmdline_opts): # Preserve current $PATH variable. Some shells (e.g. fish) are not in the default $PATH. current_path = os.environ.get("PATH") + # Python 3.12+ no longer implicitly creates an event loop; iterm2 requires one to exist. + try: + asyncio.get_event_loop() + except RuntimeError: + asyncio.set_event_loop(asyncio.new_event_loop()) + # Execute the SSH sessions iterm2.run_until_complete( exec_in_iterm(groups, cmdline_opts, global_opts, current_path)