1313 Union ,
1414)
1515from pydantic import StrictStr
16- from websockets .client import WebSocketClientProtocol , connect
16+ from websockets .client import WebSocketClientProtocol , unix_connect
1717from websockets .exceptions import (
1818 ConnectionClosedError ,
1919 WebSocketException ,
2828 OutputType ,
2929 UnexpectedEndOfExecution ,
3030)
31- from consts import JUPYTER_BASE_URL
31+ from consts import JUPYTER_BASE_URL , JUPYTER_SOCKET_PATH
3232from errors import ExecutionError
3333from envs import get_envs
3434
@@ -67,7 +67,7 @@ def __init__(self, context_id: str, session_id: str, language: str, cwd: str):
6767 self .language = language
6868 self .cwd = cwd
6969 self .context_id = context_id
70- self .url = f"ws://localhost:8888 /api/kernels/{ context_id } /channels"
70+ self .url = f"ws://localhost/api/kernels/{ context_id } /channels"
7171 self .session_id = session_id
7272 self ._executions : Dict [str , Execution ] = {}
7373 self ._lock = asyncio .Lock ()
@@ -87,8 +87,9 @@ async def connect(self):
8787 ws_logger = logger .getChild ("websockets.client" )
8888 ws_logger .setLevel (logging .ERROR )
8989
90- self ._ws = await connect (
91- self .url ,
90+ self ._ws = await unix_connect (
91+ JUPYTER_SOCKET_PATH ,
92+ uri = self .url ,
9293 ping_timeout = PING_TIMEOUT ,
9394 max_size = None ,
9495 max_queue = None ,
@@ -104,7 +105,10 @@ async def connect(self):
104105 async def interrupt (self ):
105106 """Interrupt the current kernel execution via the Jupyter REST API."""
106107 try :
107- async with httpx .AsyncClient () as client :
108+ async with httpx .AsyncClient (
109+ transport = httpx .AsyncHTTPTransport (uds = JUPYTER_SOCKET_PATH ),
110+ trust_env = False ,
111+ ) as client :
108112 response = await client .post (
109113 f"{ JUPYTER_BASE_URL } /api/kernels/{ self .context_id } /interrupt"
110114 )
0 commit comments