-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added detach mode to cli serve command
- Loading branch information
1 parent
c49073c
commit 4b84304
Showing
5 changed files
with
51 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
import argparse | ||
import json | ||
import sys | ||
import subprocess | ||
import time | ||
from typing import Optional | ||
|
||
|
||
def run(argv): | ||
if len(argv) <= 1: | ||
print("_daemon_: Warning: empty daemon_config") | ||
daemon_config = None | ||
def run(config): | ||
from .server_process import server_process | ||
|
||
server_process(config) | ||
|
||
|
||
def start(config) -> Optional[int]: | ||
"""start a server as background daemon | ||
Args: | ||
config (dict): server launch config | ||
Returns: | ||
DaemonableProcess: the daemon process | ||
""" | ||
from neetbox.utils import DaemonableProcess | ||
import neetbox.server._daemon_server_launch_script as myself | ||
|
||
popen = DaemonableProcess( # server daemon | ||
target=myself, | ||
args=["--config", json.dumps(config)], | ||
mode=config["mode"], | ||
redirect_stdout=subprocess.DEVNULL if config["mute"] else None, | ||
env_append={"NEETBOX_DAEMON_PROCESS": "1"}, | ||
).start() | ||
time.sleep(1) | ||
return popen | ||
|
||
|
||
if __name__ == "__main__": | ||
print("server starting.\n name:\t", __name__, "\nargs:\t", sys.argv) | ||
if len(sys.argv) <= 1: | ||
print("Warning: empty server config") | ||
config = None | ||
else: | ||
ap = argparse.ArgumentParser() | ||
ap.add_argument("--config") | ||
args = ap.parse_args() | ||
print(type(args.config)) | ||
print(args.config) | ||
daemon_config = json.loads(args.config) | ||
print("Daemon started with config:", daemon_config) | ||
from .server_process import server_process | ||
|
||
server_process(daemon_config) | ||
|
||
|
||
if __name__ == "__main__": | ||
print("daemon server starting.\n name:\t", __name__, "\nargs:\t", sys.argv) | ||
run(sys.argv) | ||
print("daemon server exiting.") | ||
config = json.loads(args.config) | ||
print("Daemon started with config:", config) | ||
run(config) | ||
print("server closed.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "neetbox" | ||
version = "0.4.10" | ||
version = "0.4.11" | ||
description = "Logging/Debugging/Tracing/Managing/Facilitating long running python projects, especially a replacement of tensorboard for deep learning projects" | ||
license = "MIT" | ||
authors = ["VisualDust <[email protected]>", "Lideming <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters