fix no such directory error when running server

and added a 0.5 sleep time between disconnecting and killing server
This commit is contained in:
Ziad-I
2024-06-17 13:44:40 +03:00
committed by Dion Moult
parent 0aad3d99b5
commit bd30f73b3a
+10 -2
View File
@@ -26,6 +26,7 @@ import webbrowser
import asyncio
import socketio
import threading
from time import sleep
sio = None
ws_process = None
@@ -54,8 +55,12 @@ class Web(blenderbim.core.tool.Web):
@classmethod
def start_websocket_server(cls, port):
global ws_process
ws_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "webui", "sioserver.py")
ws_process = subprocess.Popen(["python", ws_path, "--p", str(port), "--host", "127.0.0.1"])
webui_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "webui")
ws_path = os.path.join(webui_path, "sioserver.py")
ws_process = subprocess.Popen(["python", ws_path, "--p", str(port), "--host", "127.0.0.1"], cwd=webui_path)
cls.open_web_browser(port)
cls.set_is_running(True)
@@ -98,9 +103,12 @@ class Web(blenderbim.core.tool.Web):
if bpy.context.scene.WebProperties.is_connected:
cls.disconnect_websocket_server()
sleep(0.5)
ws_process.terminate()
ws_process.wait()
ws_process = None
cls.set_is_running(False)
print("Websocket server terminated successfully")