Skip to content

Commit

Permalink
Merge pull request #392 from ExaWorks/fix_throttle_test
Browse files Browse the repository at this point in the history
Properly synchronize before incrementing current_job_index, otherwise
  • Loading branch information
hategan authored Jul 28, 2023
2 parents 50f4bc7 + eda2c79 commit 887b02a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/test_doc_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Since they are actively tested against, they are certain to be
up-to-date and to work as intended.
"""

import threading
import time
import pathlib
import typing
Expand Down Expand Up @@ -60,14 +60,16 @@ def __init__(self, total_jobs: int, max_active_jobs: int) -> None:
self.current_job_index = 0
self.total_jobs = total_jobs
self.max_active_jobs = max_active_jobs
self.lock = threading.RLock()
if total_jobs < 1 or max_active_jobs < 1:
raise ValueError("total_jobs and max_active_jobs must be > 0")

def submit_next(self) -> None:
"""Submit the next job in the queue."""
if self.current_job_index < self.total_jobs:
self.jex.submit(self.jobs[self.current_job_index])
self.current_job_index += 1
with self.lock:
if self.current_job_index < self.total_jobs:
self.jex.submit(self.jobs[self.current_job_index])
self.current_job_index += 1

def start(self) -> None:
"""Begin submission of jobs."""
Expand Down

0 comments on commit 887b02a

Please sign in to comment.