Skip to content

Commit

Permalink
fixed websockt thread not exiting with main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 24, 2023
1 parent 94d6d3c commit b8f9014
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions neetbox/daemon/client/_action_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def run_and_callback(target_action, params, callback):
Thread(
target=run_and_callback,
kwargs={"target_action": target_action, "params": params, "callback": callback},
daemon=True,
).start()
return None
else: # blocking run
Expand Down
8 changes: 3 additions & 5 deletions neetbox/daemon/client/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ class ClientConn(metaclass=Singleton):
__ws_subscription = Registry("__client_ws_subscription") # { event-type-name : list(Callable)}

def __init__(self) -> None:
cfg = get_module_level_config()
_root_config = get_module_level_config("@")
ClientConn._display_name = cfg["displayName"] or _root_config["name"]

def __load_http_client():
__local_http_client = httpx.Client(
proxies={
Expand All @@ -67,6 +63,8 @@ def __load_http_client():

def _init_ws():
cfg = get_module_level_config()
_root_config = get_module_level_config("@")
ClientConn._display_name = cfg["displayName"] or _root_config["name"]

# ws server url
ClientConn.ws_server_addr = f"ws://{cfg['host']}:{cfg['port'] + 1}{CLIENT_API_ROOT}"
Expand All @@ -83,7 +81,7 @@ def _init_ws():
on_close=ClientConn.__on_ws_close,
)

Thread(target=ws.run_forever, kwargs={"reconnect": True}).start()
Thread(target=ws.run_forever, kwargs={"reconnect": True}, daemon=True).start()

# assign self to websocket log writer
from neetbox.logging._writer import _assign_connection_to_WebSocketLogWriter
Expand Down
4 changes: 1 addition & 3 deletions neetbox/daemon/client/_daemon_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def _check_daemon_alive(_api_addr):
global __upload_thread
if __upload_thread is None or not __upload_thread.is_alive():
__upload_thread = Thread(
target=_upload_thread,
daemon=True,
args=[cfg, _base_addr, _display_name],
target=_upload_thread, args=[cfg, _base_addr, _display_name], daemon=True
)
__upload_thread.start()

Expand Down
4 changes: 3 additions & 1 deletion neetbox/pipeline/_signal_and_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def _so_update_and_ping_listen(_name, _value, _watch_config):
f"Watched value {_name} takes longer time({delta_t:.8f}s) to update than it was expected({expected_time_limit}s)."
)

Thread(target=_so_update_and_ping_listen, args=(name, _the_value, _watch_config)).start()
Thread(
target=_so_update_and_ping_listen, args=(name, _the_value, _watch_config), daemon=True
).start()
return _the_value


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pytest = "^7.4.3"
pyfiglet = "^1.0.2"
httpx = "^0.24.0"
flask = "^2.2.3"
flask-socketio = "^5.3.6"
websocket-client = "^1.6.4"
websocket-server = "^0.6.4"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
Expand Down

0 comments on commit b8f9014

Please sign in to comment.