Skip to content

Commit 20f8645

Browse files
committed
Fix busy waiting
1 parent 466818c commit 20f8645

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pyhealth/datasets/base_dataset.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,11 @@ def _task_transform(self, task: BaseTask, output_dir: Path, num_workers: int) ->
709709
with ctx.Pool(processes=num_workers, initializer=_task_transform_init, initargs=(queue,)) as pool:
710710
result = pool.map_async(_task_transform_fn, args_list) # type: ignore
711711
with tqdm(total=len(patient_ids)) as progress:
712-
# TODO: this is busy-waiting, can we do better?
713712
while not result.ready():
714-
while not queue.empty():
715-
progress.update(queue.get())
713+
try:
714+
progress.update(queue.get(timeout=1))
715+
except:
716+
pass
716717

717718
# remaining items
718719
while not queue.empty():
@@ -759,8 +760,10 @@ def _proc_transform(self, task_df: Path, output_dir: Path, num_workers: int) ->
759760
result = pool.map_async(_proc_transform_fn, args_list) # type: ignore
760761
with tqdm(total=num_samples) as progress:
761762
while not result.ready():
762-
while not queue.empty():
763-
progress.update(queue.get())
763+
try:
764+
progress.update(queue.get(timeout=1))
765+
except:
766+
pass
764767

765768
# remaining items
766769
while not queue.empty():

0 commit comments

Comments
 (0)