Skip to content

Commit 77ca1a5

Browse files
committed
change asyncio.start_server to use host 0.0.0.0 instead of localhost from client
1 parent 2957aed commit 77ca1a5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

custom_components/pyscript/jupyter_kernel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import json
1515
import logging
1616
import logging.handlers
17-
import random
1817
import re
1918
from struct import pack, unpack
2019
import traceback
@@ -205,7 +204,8 @@ def __init__(self, config, ast_ctx, global_ctx_name, global_ctx_mgr):
205204
self.control_port = None
206205
self.stdin_port = None
207206
self.shell_port = None
208-
self.avail_port = random.randrange(40000, 50000)
207+
# this should probably be a configuration parameter
208+
self.avail_port = 50321
209209

210210
# there can be multiple iopub subscribers, with corresponding tasks
211211
self.iopub_socket = set()
@@ -684,13 +684,14 @@ async def startup_timeout(self):
684684

685685
async def start_one_server(self, callback):
686686
"""Start a server by finding an available port."""
687+
first_port = self.avail_port
687688
for _ in range(2048):
688689
try:
689-
server = await asyncio.start_server(callback, self.config["ip"], self.avail_port)
690+
server = await asyncio.start_server(callback, "0.0.0.0", self.avail_port)
690691
return server, self.avail_port
691692
except OSError:
692693
self.avail_port += 1
693-
_LOGGER.error("unable to find an available port on host %s, last port %d", self.config["ip"], self.avail_port)
694+
_LOGGER.error("unable to find an available port from %d to %d", first_port, self.avail_port - 1)
694695
return None, None
695696

696697
def get_ports(self):

0 commit comments

Comments
 (0)