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 60fb2fc1..9340942d 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 53b07c6d..59d99e09 100644 --- a/neetbox/daemon/_flask_server.py +++ b/neetbox/daemon/_flask_server.py @@ -4,6 +4,7 @@ # URL: https://gong.host # Date: 20230414 +import os import sys import time from threading import Thread @@ -11,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 @@ -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 = list(_STAT_POOL.keys()) + _names = {"names": list(_STAT_POOL.keys())} return _names @api.route("/sync/", methods=["POST"]) @@ -74,11 +68,11 @@ 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 +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"]) + 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, + "mode": "detached", + "displayName": None, + "uploadInterval": 10, + "mute": True, + "launcher": { + "port": 20202, + }, + } + ) diff --git a/pyproject.toml b/pyproject.toml index 673952ed..3a56f971 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"