move intial opening of browser to server on startup event

as a band aid fix to handle race condition between starting server and opening of web browser
This commit is contained in:
Ziad-I
2024-07-18 23:00:52 +03:00
committed by Dion Moult
parent f50bbf9704
commit 386caab840
2 changed files with 10 additions and 1 deletions
@@ -1,5 +1,6 @@
import sys
import os
import webbrowser
blenderbim_path = os.environ.get("blenderbim_path")
if blenderbim_path:
@@ -119,10 +120,15 @@ async def gantt(request):
return web.Response(text=html_content, content_type="text/html")
async def open_web_browser(app):
webbrowser.open(f"http://127.0.0.1:{sio_port}/")
app.router.add_get("/", index)
app.router.add_get("/gantt", gantt)
app.router.add_static("/jsgantt/", path="../gantt", name="jsgantt")
app.router.add_static("/static/", path="./static", name="static")
app.on_startup.append(open_web_browser)
def main():
+4 -1
View File
@@ -84,7 +84,10 @@ class Web(blenderbim.core.tool.Web):
ws_process = subprocess.Popen(
[sys.executable, ws_path, "--p", str(port), "--host", "127.0.0.1"], cwd=webui_path, env=env
)
cls.open_web_browser(port)
# moved intial opening of web browser to server on startup event
# to handle race condition between starting server and openning browser
# TODO: a better way to handle race condition
# cls.open_web_browser(port)
cls.set_is_running(True)
@classmethod