Skip to content

Commit

Permalink
Adapt to using greenlet runner
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Feb 1, 2025
1 parent 6139cf1 commit a7f67e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
38 changes: 20 additions & 18 deletions src/plumpy/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,13 +1316,27 @@ def execute(self) -> dict[str, Any] | None:
"""
from .reentry import _get_runner

if self.has_terminated():
return self.result()
if not self.has_terminated():
coro = self.step_until_terminated()
with _get_runner() as runner:
result = runner.run(coro)

return result

else:
self.result()

async def step_until_terminated(self) -> Any:
"""If the process has not terminated,
run the current step and wait until the step finished.
runner = _get_runner()
with runner as runner:
return runner.run(self.step_until_terminated())
# return asyncio.run(self.step_until_terminated())
This is the function run by the event loop (not ``step``).
"""
while not self.has_terminated():
await self.step()

return await self.future()

@ensure_not_closed
async def step(self) -> None:
Expand Down Expand Up @@ -1378,18 +1392,6 @@ async def step(self) -> None:
self._stepping = False
self._set_interrupt_action(None)

async def step_until_terminated(self) -> Any:
"""If the process has not terminated,
run the current step and wait until the step finished.
This is the function run by the event loop (not ``step``).
"""
while not self.has_terminated():
await self.step()

return await self.future()

# endregion

@ensure_not_closed
Expand Down
4 changes: 0 additions & 4 deletions tests/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def on_kill(self, msg):
super().on_kill(msg)


@pytest.mark.usefixtures('custom_event_loop_policy')
def test_process_is_savable():
proc = utils.DummyProcess()
assert isinstance(proc, Savable)
Expand Down Expand Up @@ -71,7 +70,6 @@ async def task(self, steps: list):


class TestProcess:
@pytest.mark.usefixtures('custom_event_loop_policy')
def test_spec(self):
"""
Check that the references to specs are doing the right thing...
Expand Down Expand Up @@ -586,7 +584,6 @@ def run(self):
proc = StackTest()
proc.execute()

@pytest.mark.usefixtures('custom_event_loop_policy')
def test_process_stack_multiple(self):
"""
Run multiple and nested processes to make sure the process stack is always correct
Expand Down Expand Up @@ -622,7 +619,6 @@ def run(self):

assert len(expect_true) == n_run * 3

@pytest.mark.usefixtures('custom_event_loop_policy')
def test_process_nested(self):
"""
Run multiple and nested processes to make sure the process stack is always correct
Expand Down

0 comments on commit a7f67e0

Please sign in to comment.