Skip to content

Commit

Permalink
: More
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkwah committed Dec 14, 2023
1 parent 0a889b3 commit d710981
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/ert/scheduler/local_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from ert.scheduler.driver import Driver, JobEvent

_TERMINATE_TIMEOUT = 10.0


class LocalDriver(Driver):
def __init__(self) -> None:
Expand Down Expand Up @@ -66,4 +68,8 @@ async def _wait(self, proc: Process) -> bool:
async def _kill(self, proc: Process) -> None:
"""This method exists to allow for mocking it in tests"""
proc.terminate()
await proc.wait()
try:
await asyncio.wait_for(proc.wait(), _TERMINATE_TIMEOUT)
except asyncio.TimeoutError:
proc.kill()
await proc.wait()
4 changes: 1 addition & 3 deletions src/ert/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ async def ainit(self) -> None:
if self._events is None:
self._events = asyncio.Queue()

def add_realization(
self, real: Realization, callback_timeout: Callable[[int], None]
) -> None:
def add_realization(self, real: Realization, callback_timeout: Any = None) -> None:
self._jobs[real.iens] = Job(self, real)

def kill_all_jobs(self) -> None:
Expand Down
11 changes: 8 additions & 3 deletions tests/unit_tests/scheduler/test_local_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from ert.scheduler import local_driver
from ert.scheduler.driver import JobEvent
from ert.scheduler.local_driver import LocalDriver

Expand Down Expand Up @@ -43,11 +44,15 @@ async def test_kill(tmp_path):
assert await driver.event_queue.get() == (42, JobEvent.ABORTED)


async def test_kill_unresponsive_process(tmp_path):
@pytest.mark.timeout(5)
async def test_kill_unresponsive_process(monkeypatch, tmp_path):
# Reduce timeout to something more appropriate for a test
monkeypatch.setattr(local_driver, "_TERMINATE_TIMEOUT", 0.1)

(tmp_path / "script").write_text(
"""\
trap "" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
sleep 10
trap "" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
sleep 60
"""
)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def init(iens, exec, *args, cwd):
driver = mock_driver(init=init)

sch = scheduler.Scheduler(driver)
sch.add_realization(realization, callback_timeout=lambda _: None)
sch.add_realization(realization)

assert await sch.execute() == EVTYPE_ENSEMBLE_STOPPED
assert await future == realization.iens
Expand All @@ -73,7 +73,7 @@ async def kill():

driver = mock_driver(wait=wait, kill=kill)
sch = scheduler.Scheduler(driver)
sch.add_realization(realization, callback_timeout=lambda _: None)
sch.add_realization(realization)

scheduler_task = asyncio.create_task(sch.execute())

Expand Down

0 comments on commit d710981

Please sign in to comment.