Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 24, 2023
1 parent 7bcc1bd commit 7332dc2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
3 changes: 3 additions & 0 deletions neetbox/daemon/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 11 additions & 5 deletions neetbox/daemon/server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down
3 changes: 3 additions & 0 deletions tests/client/readme.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions tests/client/test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7332dc2

Please sign in to comment.