Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions aiomultiprocess/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __await__(self) -> Any:
return self.join().__await__()

@staticmethod
def run_async(unit: Unit) -> R:
def run_async(unit: Unit) -> Optional[R]:
"""Initialize the child process and event loop, then execute the coroutine."""
try:
if unit.loop_initializer is None:
Expand All @@ -143,7 +143,8 @@ def run_async(unit: Unit) -> R:
result: R = loop.run_until_complete(unit.target(*unit.args, **unit.kwargs))

return result

except KeyboardInterrupt:
return None
except BaseException:
log.exception(f"aio process {os.getpid()} failed")
raise
Expand Down Expand Up @@ -216,13 +217,14 @@ def __init__(self, *args, **kwargs) -> None:
self.unit.namespace.result = None

@staticmethod
def run_async(unit: Unit) -> R:
def run_async(unit: Unit) -> Optional[R]:
"""Initialize the child process and event loop, then execute the coroutine."""
try:
result: R = Process.run_async(unit)
result: Optional[R] = Process.run_async(unit)
unit.namespace.result = result
return result

except KeyboardInterrupt:
return None
except BaseException as e:
unit.namespace.result = e
raise
Expand Down
4 changes: 4 additions & 0 deletions aiomultiprocess/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ async def raise_fn():
raise RuntimeError("raising")


async def raise_keyboard_interrupt():
raise KeyboardInterrupt()


async def terminate(process):
await asyncio.sleep(0.5)
process.terminate()
Expand Down
8 changes: 8 additions & 0 deletions aiomultiprocess/tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_dummy_constant,
initializer,
raise_fn,
raise_keyboard_interrupt,
sleepy,
two,
)
Expand Down Expand Up @@ -223,6 +224,13 @@ async def test_raise(self):
)
self.assertIsInstance(result, RuntimeError)

@async_test
async def test_keyboard_interrupt(self):
result = await amp.Worker(
target=raise_keyboard_interrupt, name="test_process", initializer=do_nothing
)
self.assertIsNone(result)

@async_test
async def test_sync_target(self):
with self.assertRaises(ValueError) as _:
Expand Down