From bffbacd6a633cba5001e02b72448066a7871bbdd Mon Sep 17 00:00:00 2001 From: VisualDust Date: Tue, 21 Nov 2023 17:01:01 +0800 Subject: [PATCH 1/2] minor fix --- neetbox/daemon/_flask_server.py | 37 ++++++++++++++++++++------------- pyproject.toml | 5 +++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/neetbox/daemon/_flask_server.py b/neetbox/daemon/_flask_server.py index 15ad0ce4..500b622e 100644 --- a/neetbox/daemon/_flask_server.py +++ b/neetbox/daemon/_flask_server.py @@ -4,13 +4,7 @@ # URL: https://gong.host # Date: 20230414 -from neetbox.utils import pkg -from neetbox.utils.framing import get_frame_module_traceback - -module_name = get_frame_module_traceback().__name__ -assert pkg.is_installed( - "flask", try_install_if_not=True -), f"{module_name} requires flask which is not installed" +import os import sys import time from threading import Thread @@ -52,11 +46,11 @@ def return_status_of(name): return _returning_stat @api.route("/status/list", methods=["GET"]) - def return_names_of_status(name): + def return_names_of_status(): global __COUNT_DOWN global _STAT_POOL __COUNT_DOWN = __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC - _names = {_STAT_POOL.keys()} + _names = {"names": list(_STAT_POOL.keys())} return _names @api.route("/sync/", methods=["POST"]) @@ -74,11 +68,13 @@ def shutdown(): __COUNT_DOWN = -1 def __sleep_and_shutdown(secs=3): - time.sleep(secs=secs) - sys.exit(0) + time.sleep(secs) + os._exit(0) - Thread(target=__sleep_and_shutdown, args=(3)).start() # shutdown after 3 seconds - return "ok" + Thread( + target=__sleep_and_shutdown + ).start() # shutdown after 3 seconds + return f"shutdown in {3} seconds." def _count_down_thread(): global __COUNT_DOWN @@ -91,4 +87,17 @@ def _count_down_thread(): count_down_thread = Thread(target=_count_down_thread, daemon=True) count_down_thread.start() - api.run(host="0.0.0.0", port=daemon_config["port"]) + api.run(host="0.0.0.0", port=daemon_config["port"], debug=True) + +if __name__ == '__main__': + daemon_process({ + "enable": True, + "server": "localhost", + "port": 20202, + "mode": "detached", + "displayName": None, + "uploadInterval": 10, + "mute": True, + "launcher": { + "port": 20202, + }}) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9385ae57..9d54429d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,11 +5,11 @@ description = "NEETBox contains useless CV code snippets." license = "MIT" authors = ["VisualDust "] maintainers = [ + "PaperCube ", "VisualDust ", + "Lideming ", "PommesPeter ", - "PaperCube ", "PuQing ", - "Lideming " ] @@ -44,6 +44,7 @@ pillow = "^10.0.1" pre-commit = ">=3.4.0" click = "^8.1.7" pytest = "^7.4.3" +pyfiglet = "^1.0.2" [tool.poetry.group.dev.dependencies] pytest = "^7.0.0" From d8446e93405429d1c0a328dd4e3fe1e5a045def6 Mon Sep 17 00:00:00 2001 From: VisualDust Date: Tue, 21 Nov 2023 17:09:07 +0800 Subject: [PATCH 2/2] minor fix --- neetbox/config/_config.py | 2 +- neetbox/daemon/__init__.py | 5 ---- neetbox/daemon/_flask_server.py | 43 +++++++++++++++------------------ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/neetbox/config/_config.py b/neetbox/config/_config.py index 313724f1..307938b8 100644 --- a/neetbox/config/_config.py +++ b/neetbox/config/_config.py @@ -35,7 +35,7 @@ "daemon": { "enable": True, "allowIpython": False, - "server": "localhost", + "server": "0.0.0.0", "port": 20202, "mode": "detached", "displayName": None, diff --git a/neetbox/daemon/__init__.py b/neetbox/daemon/__init__.py index a5baaf94..7c70191c 100644 --- a/neetbox/daemon/__init__.py +++ b/neetbox/daemon/__init__.py @@ -12,10 +12,6 @@ from neetbox.daemon.daemonable_process import DaemonableProcess from neetbox.logging import logger from neetbox.pipeline import listen, watch -from neetbox.utils import pkg - -pkg.is_installed("flask", try_install_if_not=True) -pkg.is_installed("setproctitle", try_install_if_not=True) def __attach_daemon(daemon_config): @@ -30,7 +26,6 @@ def __attach_daemon(daemon_config): "ipython, try to set 'allowIpython' to True." ) return False # ignore if debugging in ipython - pkg.is_installed("flask", try_install_if_not=True) _online_status = connect_daemon(daemon_config) # try to connect daemon logger.log("daemon connection status: " + str(_online_status)) if not _online_status: # if no daemon online diff --git a/neetbox/daemon/_flask_server.py b/neetbox/daemon/_flask_server.py index 4b1eaab7..59d99e09 100644 --- a/neetbox/daemon/_flask_server.py +++ b/neetbox/daemon/_flask_server.py @@ -4,7 +4,7 @@ # URL: https://gong.host # Date: 20230414 -import os +import os import sys import time from threading import Thread @@ -12,13 +12,6 @@ from flask import Flask, abort, json, request from neetbox.config import get_module_level_config -from neetbox.utils import pkg -from neetbox.utils.framing import get_frame_module_traceback - -module_name = get_frame_module_traceback().__name__ # type: ignore -assert pkg.is_installed( - "flask", try_install_if_not=True -), f"{module_name} requires flask which is not installed" _STAT_POOL = {} __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC = 60 * 60 * 12 # 12 Hours @@ -78,9 +71,7 @@ def __sleep_and_shutdown(secs=3): time.sleep(secs) os._exit(0) - Thread( - target=__sleep_and_shutdown - ).start() # shutdown after 3 seconds + Thread(target=__sleep_and_shutdown).start() # shutdown after 3 seconds return f"shutdown in {3} seconds." def _count_down_thread(): @@ -94,17 +85,21 @@ def _count_down_thread(): count_down_thread = Thread(target=_count_down_thread, daemon=True) count_down_thread.start() - api.run(host="0.0.0.0", port=daemon_config["port"], debug=True) - -if __name__ == '__main__': - daemon_process({ - "enable": True, - "server": "localhost", - "port": 20202, - "mode": "detached", - "displayName": None, - "uploadInterval": 10, - "mute": True, - "launcher": { + api.run(host=daemon_config["server"], port=daemon_config["port"], debug=True) + + +if __name__ == "__main__": + daemon_process( + { + "enable": True, + "server": "0.0.0.0", "port": 20202, - }}) \ No newline at end of file + "mode": "detached", + "displayName": None, + "uploadInterval": 10, + "mute": True, + "launcher": { + "port": 20202, + }, + } + )