From 9aba2740708f5c1a88c3bbc1e7306d4dcc94ae56 Mon Sep 17 00:00:00 2001 From: Ziad-I <68874104+Ziad-I@users.noreply.github.com> Date: Tue, 13 Aug 2024 03:12:56 +0300 Subject: [PATCH] make has_started check for both pid and port this solves the issue when a user has not killed a previous server so the port of that server wasn't removed from the pid file, which would make has_started return true even if server hasn't started yet. --- src/bonsai/bonsai/tool/web.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/tool/web.py b/src/bonsai/bonsai/tool/web.py index 932b27d191..22784a368a 100644 --- a/src/bonsai/bonsai/tool/web.py +++ b/src/bonsai/bonsai/tool/web.py @@ -231,6 +231,7 @@ class Web(bonsai.core.tool.Web): Returns: bool: True if the WebSocket server has started on the specified port within the maximum time limit, False otherwise. """ + pid = ws_process.pid max_time = 5 start = time.time() while True: @@ -241,7 +242,7 @@ class Web(bonsai.core.tool.Web): try: with open(pid_file, "r") as f: data = json.load(f) - if port in data.values(): + if data.get(str(pid)) == port: return True except: pass