Skip to content

Commit

Permalink
Merge branch 'develop' into process_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Mar 9, 2021
2 parents 2b6ef68 + 56edeae commit 7c08e11
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
6 changes: 6 additions & 0 deletions plumpy/process_states.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import asyncio
from enum import Enum
import sys
import traceback
Expand Down Expand Up @@ -232,6 +233,11 @@ async def execute(self) -> State: # type: ignore # pylint: disable=invalid-over
except Interruption:
# Let this bubble up to the caller
raise
except asyncio.CancelledError: # pylint: disable=try-except-raise
# note this re-raise is only required in python<=3.7,
# for python>=3.8 asyncio.CancelledError does not inherit from Exception,
# so will not be caught below
raise
except Exception: # pylint: disable=broad-except
excepted = self.create_state(ProcessState.EXCEPTED, *sys.exc_info()[1:])
return cast(State, excepted)
Expand Down
22 changes: 16 additions & 6 deletions plumpy/processes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# -*- coding: utf-8 -*-
"""The main Process module"""
import abc
import asyncio
import contextlib
import copy
import enum
import functools
import copy
import logging
import time
import sys
import uuid
import asyncio
import time
from types import TracebackType
from typing import (
Any, Awaitable, Callable, cast, Dict, Generator, Hashable, List, Optional, Sequence, Tuple, Type, Union
)
import uuid
import warnings

try:
from aiocontextvars import ContextVar
Expand Down Expand Up @@ -481,9 +482,12 @@ def exception(self) -> Optional[BaseException]:
return None

def done(self) -> bool:
"""Return True if the call was successfully killed or finished running.
.. deprecated:: 0.18.6
Use the `has_terminated` method instead
"""
Return True if the call was successfully killed or finished running.
"""
warnings.warn('method is deprecated, use `has_terminated` instead', DeprecationWarning) # pylint: disable=no-member
return self._state.is_terminal()

# endregion
Expand Down Expand Up @@ -1193,6 +1197,12 @@ async def step(self) -> None:

except KeyboardInterrupt: # pylint: disable=try-except-raise
raise
except asyncio.CancelledError: # pylint: disable=try-except-raise
# note this re-raise is only required in python<=3.7,
# where asyncio.CancelledError == concurrent.futures.CancelledError
# it is encountered when the run_task is cancelled
# for python>=3.8 asyncio.CancelledError does not inherit from Exception, so will not be caught below
raise
except Exception: # pylint: disable=broad-except
# Overwrite the next state to go to excepted directly
next_state = self.create_state(process_states.ProcessState.EXCEPTED, *sys.exc_info()[1:])
Expand Down
10 changes: 5 additions & 5 deletions test/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_execute(self):
proc = utils.DummyProcessWithOutput()
proc.execute()

self.assertTrue(proc.done())
self.assertTrue(proc.has_terminated())
self.assertEqual(proc.state, ProcessState.FINISHED)
self.assertEqual(proc.outputs, {'default': 5})

Expand Down Expand Up @@ -331,7 +331,7 @@ def test_wait_continue(self):
proc.execute()

# Check it's done
self.assertTrue(proc.done())
self.assertTrue(proc.has_terminated())
self.assertEqual(proc.state, ProcessState.FINISHED)

def test_exc_info(self):
Expand All @@ -344,7 +344,7 @@ def test_exc_info(self):
def test_run_done(self):
proc = utils.DummyProcess()
proc.execute()
self.assertTrue(proc.done())
self.assertTrue(proc.has_terminated())

def test_wait_pause_play_resume(self):
"""
Expand All @@ -371,7 +371,7 @@ async def async_test():
await proc.future()

# Check it's done
self.assertTrue(proc.done())
self.assertTrue(proc.has_terminated())
self.assertEqual(proc.state, ProcessState.FINISHED)

loop.create_task(proc.step_until_terminated())
Expand Down Expand Up @@ -412,7 +412,7 @@ async def async_test():
loop.create_task(proc.step_until_terminated())
loop.run_until_complete(async_test())

self.assertTrue(proc.done())
self.assertTrue(proc.has_terminated())
self.assertEqual(proc.state, ProcessState.FINISHED)

def test_kill_in_run(self):
Expand Down
2 changes: 1 addition & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __init__(self, proc):

def capture(self):
self._save(self.process)
if not self.process.done():
if not self.process.has_terminated():
try:
self.process.execute()
except Exception:
Expand Down

0 comments on commit 7c08e11

Please sign in to comment.