Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
saramsey committed Nov 30, 2023
1 parent 8af6315 commit 0de6478
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions code/UI/OpenAPI/python-flask-server/KG2/openapi_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)


FLASK_DEFAULT_TCP_PORT = 5008
global child_pid
child_pid = None
global parent_pid
parent_pid = None

CONFIG_FILE = 'openapi_server/flask_config.json'


def main():

Expand All @@ -42,13 +46,15 @@ def main():

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

parent_pid = os.getpid()

pid = os.fork()
if pid == 0: # I am the child process
from ARAX_background_tasker import ARAXBackgroundTasker
Expand All @@ -58,7 +64,8 @@ def main():
f"::run_tasks [port={tcp_port}]")
eprint("Starting background tasker in a child process")
try:
ARAXBackgroundTasker(run_kp_info_cacher=False).run_tasks()
ARAXBackgroundTasker(parent_pid,
run_kp_info_cacher=False).run_tasks()
except Exception as e:
eprint("Error in ARAXBackgroundTasker.run_tasks()")
eprint(traceback.format_exc())
Expand Down Expand Up @@ -113,10 +120,7 @@ def receive_sigpipe(signal_number, frame):

# Start the service
eprint(f"Background tasker is running in child process {pid}")
global child_pid
child_pid = pid
global parent_pid
parent_pid = os.getpid()
signal.signal(signal.SIGCHLD, receive_sigchld)
signal.signal(signal.SIGPIPE, receive_sigpipe)
signal.signal(signal.SIGTERM, receive_sigterm)
Expand Down

0 comments on commit 0de6478

Please sign in to comment.