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 0de6478 commit 558954b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions code/ARAX/ARAXQuery/ARAX_background_tasker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)

class ARAXBackgroundTasker:

def __init__(self, run_kp_info_cacher=True):
def __init__(self, parent_pid: int,
run_kp_info_cacher: bool = True):
self.run_kp_info_cacher = run_kp_info_cacher
self.parent_pid = parent_pid
timestamp = str(datetime.datetime.now().isoformat())
eprint(f"{timestamp}: INFO: ARAXBackgroundTasker created")

Expand Down Expand Up @@ -116,6 +118,10 @@ def run_tasks(self):
# Loop forever doing various things
my_pid = os.getpid()
while True:
if not psutil.pid_exists(self.parent_pid):
eprint("INFO: ARAXBackgroundTasker: parent process "
f"{self.parent_pid} has gone away; exiting")
sys.exit(0)

# Run the KP Info Cacher less frequently
if self.run_kp_info_cacher:
Expand Down Expand Up @@ -159,7 +165,7 @@ def run_tasks(self):


def main():
background_tasker = ARAXBackgroundTasker()
background_tasker = ARAXBackgroundTasker(os.getpid())
background_tasker.run_tasks()


Expand Down

0 comments on commit 558954b

Please sign in to comment.