Skip to content

Commit 2fdd9a8

Browse files
authored
Add event loop setup for Python 3.14 compatibility (#304)
Set a new event loop for asyncio in Python 3.14 and above. Otherwise invoking `ghstack` crashes with ``` ERROR: Fatal exception Traceback (most recent call last): File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/logs.py", line 105, in manager yield File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/cli.py", line 47, in cli_context yield shell, config, github File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/cli.py", line 281, in submit ghstack.submit.main( ~~~~~~~~~~~~~~~~~~~^ msg=message, ^^^^^^^^^^^^ ...<13 lines>... direct_opt=direct_opt, ^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/submit.py", line 259, in main submitter = Submitter(**kwargs) File "<string>", line 24, in __init__ File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/submit.py", line 379, in __post_init__ repo = ghstack.github_utils.get_github_repo_info( github=self.github, ...<4 lines>... remote_name=self.remote_name, ) File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/github_utils.py", line 71, in get_github_repo_info name_with_owner = get_github_repo_name_with_owner( sh=sh, github_url=github_url, remote_name=remote_name, ) File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/github_utils.py", line 28, in get_github_repo_name_with_owner remote_url = sh.git("remote", "get-url", remote_name) File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/shell.py", line 281, in git return self._maybe_rstrip(self.sh(*(("git",) + args), **kwargs)) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/nshulga/py3.14-local/lib/python3.14/site-packages/ghstack/shell.py", line 200, in sh loop = asyncio.get_event_loop() File "/opt/homebrew/Cellar/python@3.14/3.14.0_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/asyncio/events.py", line 715, in get_event_loop raise RuntimeError('There is no current event loop in thread %r.' % threading.current_thread().name) RuntimeError: There is no current event loop in thread 'MainThread'. ```
1 parent 0fe2792 commit 2fdd9a8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/ghstack/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import contextlib
3+
import sys
34
from typing import Generator, List, Optional, Tuple
45

56
import click
@@ -79,6 +80,12 @@ def main(
7980
"""
8081
Submit stacks of diffs to Github
8182
"""
83+
if sys.version_info >= (3, 14):
84+
# Create new event loop as asyncio.get_event_loop() throws runtime error in 3.14
85+
import asyncio as _asyncio
86+
87+
_asyncio.set_event_loop(_asyncio.new_event_loop())
88+
8289
EXIT_STACK.enter_context(ghstack.logs.manager(debug=debug))
8390

8491
if not ctx.invoked_subcommand:

0 commit comments

Comments
 (0)