Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
saramsey committed Nov 29, 2023
1 parent ac4059e commit c6c6bd7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions code/UI/OpenAPI/python-flask-server/openapi_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ def main():
raise e
del dbmanager

# Read any load configuration details for this instance
try:
with open('openapi_server/flask_config.json') as infile:
local_config = json.load(infile)
except Exception:
eprint(f"Error loading config file: {infile}")
local_config = {"port": FLASK_DEFAULT_TCP_PORT}
tcp_port = local_config['port']

pid = os.fork()
if pid == 0: # I am the child process
from ARAX_background_tasker import ARAXBackgroundTasker
sys.stdout = open('/dev/null', 'w')
sys.stdin = open('/dev/null', 'r')
setproctitle.setproctitle("python3 ARAX_background_tasker::run_tasks")
setproctitle.setproctitle("python3 ARAX_background_tasker"
f"::run_tasks [port={tcp_port}]")
eprint("Starting background tasker in a child process")
try:
ARAXBackgroundTasker().run_tasks()
Expand Down Expand Up @@ -111,16 +121,9 @@ def receive_sigpipe(signal_number, frame):
signal.signal(signal.SIGPIPE, receive_sigpipe)
signal.signal(signal.SIGTERM, receive_sigterm)

# Read any load configuration details for this instance
try:
with open('openapi_server/flask_config.json') as infile:
local_config = json.load(infile)
except Exception:
local_config = {"port": FLASK_DEFAULT_TCP_PORT}

eprint("Starting flask application in the parent process")
setproctitle.setproctitle(setproctitle.getproctitle() +
f" [port={local_config['port']}]")
f" [port={tcp_port}]")
app.run(port=local_config['port'], threaded=True)
else:
eprint("[__main__]: fork() unsuccessful")
Expand Down

0 comments on commit c6c6bd7

Please sign in to comment.