Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
AndPuQing committed Nov 21, 2023
2 parents e932bfc + d8446e9 commit db00563
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion neetbox/config/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"daemon": {
"enable": True,
"allowIpython": False,
"server": "localhost",
"server": "0.0.0.0",
"port": 20202,
"mode": "detached",
"displayName": None,
Expand Down
5 changes: 0 additions & 5 deletions neetbox/daemon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
39 changes: 25 additions & 14 deletions neetbox/daemon/_flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
# URL: https://gong.host
# Date: 20230414

import os
import sys
import time
from threading import Thread

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
Expand Down Expand Up @@ -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/<name>", methods=["POST"])
Expand All @@ -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
Expand All @@ -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,
},
}
)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ description = "NEETBox contains useless CV code snippets."
license = "MIT"
authors = ["VisualDust <[email protected]>"]
maintainers = [
"PaperCube <[email protected]>",
"VisualDust <[email protected]>",
"Lideming <[email protected]>",
"PommesPeter <[email protected]>",
"PaperCube <[email protected]>",
"PuQing <[email protected]>",
"Lideming <[email protected]>",
]


Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit db00563

Please sign in to comment.