Skip to content

Commit

Permalink
Retrieve results asynchronized vatlab/sos-notebook#303
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Dec 1, 2020
1 parent 7b2fef4 commit 7013c75
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/sos/task_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ def update_task_status(self, task_id, status):
self.running_pending_tasks.pop(task_id)
if status == 'completed':
# status changed to completed
self.task_results[task_id] = self.agent.receive_result(task_id)
self.task_results[task_id] = self._thread_workers.submit(
self.agent.receive_result,
task_id)
# for running pending tasks
if status == 'aborted' and task_id in self.running_pending_tasks:
self.pending_tasks.append(task_id)
Expand All @@ -561,8 +563,9 @@ def update_task_status(self, task_id, status):

def get_results(self, task_ids):
while True:
if all(x in self.task_status for x in task_ids):
return {x: self.task_results[x] for x in task_ids}
with threading.Lock():
if all(x in self.task_results and not self.task_results[x].running() for x in task_ids):
return {x: self.task_results[x].result() for x in task_ids}
time.sleep(0.1)

def query_tasks(self,
Expand Down

0 comments on commit 7013c75

Please sign in to comment.