diff --git a/neetbox/daemon/readme.md b/neetbox/daemon/readme.md index d977b70e..c22c2b3f 100644 --- a/neetbox/daemon/readme.md +++ b/neetbox/daemon/readme.md @@ -3,10 +3,13 @@ ## How to run server only at neetbox project root: + ```bash python neetbox/daemon/server/_server.py ``` +script above should launch a server in debug mode on `localhost:5000`, it wont read the port in `neetbox.toml`. a swegger UI is provided at [localhost:5000/docs](http://127.0.0.1:5000/docs) in debug mode. + ## WS message standard websocke messages are described in json. There is a dataclass representing websocket message: diff --git a/neetbox/daemon/server/_server.py b/neetbox/daemon/server/_server.py index 49a8fedf..08617413 100644 --- a/neetbox/daemon/server/_server.py +++ b/neetbox/daemon/server/_server.py @@ -17,8 +17,8 @@ __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC = 60 * 60 * 12 # 12 Hours __COUNT_DOWN = __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC -__DAEMON_NAME = "NEETBOX DAEMON" -setproctitle.setproctitle(__DAEMON_NAME) +__PROC_NAME = "NEETBOX SERVER" +setproctitle.setproctitle(__PROC_NAME) FRONTEND_API_ROOT = "/web" CLIENT_API_ROOT = "/cli" @@ -69,11 +69,13 @@ def ws_send(self): # =============================================================== if debug: + print("Running with debug, using APIFlask") from apiflask import APIFlask - app = APIFlask(__name__) + app = APIFlask(__PROC_NAME) else: - app = Flask(__name__) + print("Running in production mode, escaping APIFlask") + app = Flask(__PROC_NAME) # websocket server ws_server = WebsocketServer(port=cfg["port"] + 1) __BRIDGES = {} # manage connections @@ -292,7 +294,11 @@ def _count_down_thread(): count_down_thread.start() ws_server.run_forever(threaded=True) - app.run(host="0.0.0.0", port=cfg["port"], debug=debug) + + if debug: + app.run(debug=debug) # run apiflask on localhost:5000 + else: # run production mode on configured port + app.run(host="0.0.0.0", port=cfg["port"], debug=debug) if __name__ == "__main__": diff --git a/tests/client/readme.md b/tests/client/readme.md new file mode 100644 index 00000000..e04c557d --- /dev/null +++ b/tests/client/readme.md @@ -0,0 +1,3 @@ +# What is this + +this is a single file simulation representing a common case of usage of neetbox. Edit `neetbox.toml` and run `test.py` performs a general test on some neetbox behaviors. diff --git a/tests/client/test.py b/tests/client/test.py new file mode 100644 index 00000000..2ebc69d5 --- /dev/null +++ b/tests/client/test.py @@ -0,0 +1,26 @@ +import pytest + +pytest.skip(allow_module_level=True) + +from random import random +from time import sleep + +from neetbox.integrations.environment import hardware, platform +from neetbox.logging import logger +from neetbox.pipeline import listen, watch + + +@watch("train", initiative=True) +def train(epoch): + loss, acc = random(), random() + return {"loss": loss, "acc": acc} + + +@listen("train") +def print_to_console(metrix): + logger.log(f"metrix from train: {metrix}") + + +for i in range(99999): + sleep(1) + train(i)