From 01d351fa76a91667d0bcc2b22daf0271fb6c6d97 Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Tue, 21 Nov 2023 14:08:16 +0100 Subject: [PATCH] Fix some typing Also added return value to _add_realization as that is expected by other functions --- src/_ert_job_runner/job.py | 3 ++- src/ert/job_queue/driver.py | 4 ++-- src/ert/job_queue/queue.py | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/_ert_job_runner/job.py b/src/_ert_job_runner/job.py index 41b8fb508fb..c56f5d1f97c 100644 --- a/src/_ert_job_runner/job.py +++ b/src/_ert_job_runner/job.py @@ -105,7 +105,8 @@ def ensure_file_handles_closed(): f"Most likely you are missing and should add " f"'#!/usr/bin/env python' to the top of the file: " ) - stderr.write(msg) + if stderr is not None: + stderr.write(msg) ensure_file_handles_closed() yield Exited(self, e.errno).with_error(msg) return diff --git a/src/ert/job_queue/driver.py b/src/ert/job_queue/driver.py index f598934ffef..92591828bda 100644 --- a/src/ert/job_queue/driver.py +++ b/src/ert/job_queue/driver.py @@ -32,7 +32,7 @@ def has_option(self, option_key: str) -> bool: return option_key in self._options @abstractmethod - async def submit(self, realization: "QueueableRealization"): + async def submit(self, realization: "RealizationState"): pass @abstractmethod @@ -40,7 +40,7 @@ async def poll_statuses(self): pass @abstractmethod - async def kill(self, realization: "QueueableRealization"): + async def kill(self, realization: "RealizationState"): pass @classmethod diff --git a/src/ert/job_queue/queue.py b/src/ert/job_queue/queue.py index 6cd533be01c..45801fbaa3b 100644 --- a/src/ert/job_queue/queue.py +++ b/src/ert/job_queue/queue.py @@ -10,6 +10,7 @@ import logging import ssl from collections import deque +from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union from cloudevents.conversion import to_json @@ -159,10 +160,11 @@ def kill_all_jobs(self) -> None: def queue_size(self) -> int: return len(self._realizations) - def _add_realization(self, realization: QueueableRealization) -> None: + def _add_realization(self, realization: QueueableRealization) -> int: self._realizations.append( RealizationState(self, realization, retries=self._queue_config.max_submit - 1) ) + return len(self._realizations) - 1 def max_running(self) -> int: max_running = 0 @@ -360,7 +362,7 @@ def add_realization_from_run_arg( num_cpu: int, ) -> None: qreal = QueueableRealization( - job_script=job_script, + job_script=Path(job_script), run_arg=run_arg, num_cpu=num_cpu, max_runtime=max_runtime, @@ -374,7 +376,7 @@ def add_realization( callback_timeout: Optional[Callable[[int], None]] = None, ) -> None: qreal = QueueableRealization( - job_script=real.job_script, + job_script=Path(real.job_script), num_cpu=real.num_cpu, run_arg=real.run_arg, max_runtime=real.max_runtime,