Skip to content

Commit

Permalink
Undo changes asyncio.Event->bool
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Nov 26, 2024
1 parent b797a75 commit 6b66226
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/_ert/forward_model_runner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ async def main(args):
)
reporter_queue: asyncio.Queue[Message] = asyncio.Queue()

is_running = True
is_done = asyncio.Event()
forward_model_runner = ForwardModelRunner(jobs_data, reporter_queue=reporter_queue)
forward_model_runner_task = asyncio.create_task(
forward_model_runner.run(parsed_args.job)
)
reporting_task = asyncio.create_task(
handle_reporting(reporters, reporter_queue, is_running)
handle_reporting(reporters, reporter_queue, is_done)
)

def handle_sigterm(*args, **kwargs):
Expand All @@ -164,21 +164,22 @@ def handle_sigterm(*args, **kwargs):

await forward_model_runner_task

is_running = False
is_done.set()
await reporting_task


async def handle_reporting(
reporters: Sequence[reporting.Reporter],
message_queue: asyncio.Queue[Message],
is_running: bool,
is_done: asyncio.Event,
):
while True:
try:
job_status = await asyncio.wait_for(message_queue.get(), timeout=2)
except asyncio.TimeoutError:
if not is_running:
if is_done.is_set():
break
continue

logger.info(f"Job status: {job_status}")
for reporter in reporters:
Expand Down

0 comments on commit 6b66226

Please sign in to comment.