mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
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:
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
blenderbim_path = os.environ.get("blenderbim_path")
|
blenderbim_path = os.environ.get("blenderbim_path")
|
||||||
if blenderbim_path:
|
if blenderbim_path:
|
||||||
@@ -119,10 +120,15 @@ async def gantt(request):
|
|||||||
return web.Response(text=html_content, content_type="text/html")
|
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("/", index)
|
||||||
app.router.add_get("/gantt", gantt)
|
app.router.add_get("/gantt", gantt)
|
||||||
app.router.add_static("/jsgantt/", path="../gantt", name="jsgantt")
|
app.router.add_static("/jsgantt/", path="../gantt", name="jsgantt")
|
||||||
app.router.add_static("/static/", path="./static", name="static")
|
app.router.add_static("/static/", path="./static", name="static")
|
||||||
|
app.on_startup.append(open_web_browser)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ class Web(blenderbim.core.tool.Web):
|
|||||||
ws_process = subprocess.Popen(
|
ws_process = subprocess.Popen(
|
||||||
[sys.executable, ws_path, "--p", str(port), "--host", "127.0.0.1"], cwd=webui_path, env=env
|
[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)
|
cls.set_is_running(True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user