Skip to content

Ctrl-C / SIGINT fails to cancel parent on first try #4

@goodboy

Description

@goodboy

What was wrong?

Trying to cancel a program with either ctrl-c or SIGINT results in the underlying subprocess(es) being cancelled but the parent hangs waiting requiring another of the same signal to be sent wherein the program errors with (if triggered from a pytest run):

value = <trio.Nursery object at 0x7fb3b01dedc0>

    async def yield_(value=None):
>       return await _yield_(value)

value      = <trio.Nursery object at 0x7fb3b01dedc0>

env/lib/python3.8/site-packages/async_generator/_impl.py:106: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
env/lib/python3.8/site-packages/async_generator/_impl.py:99: in _yield_
    return (yield _wrap(value))
tests/core/test_open_in_process.py:77: in test_open_in_proc_cancel_via_SIGINT
    await trio.sleep_forever()
env/lib/python3.8/site-packages/async_generator/_util.py:53: in __aexit__
    await self._agen.athrow(type, value, traceback)
trio_run_in_process/run_in_process.py:191: in open_in_process
    nursery.cancel_scope.cancel()
env/lib/python3.8/site-packages/trio/_core/_run.py:725: in __aexit__
    raise combined_error_from_nursery
trio_run_in_process/run_in_process.py:67: in _relay_signals
    proc.send_signal(signum)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <trio_run_in_process.process.Process object at 0x7fb3b01debb0>, sig = 2

    def send_signal(self, sig: int) -> None:
>       os.kill(self.pid, sig)
E       ProcessLookupError: [Errno 3] No such process

self       = <trio_run_in_process.process.Process object at 0x7fb3b01debb0>
sig        = 2

Code that produced the error

I've submitted PR #5 as an addition to the test suite which demonstrates the issue(s).

Expected Result

Cancellation of both spawned subprocesses and the parent in the traditional trionic fashion.

I'm going to see what I can do to provide a fix for this. Imho this is an absolutely critical problem!

PS: on another note if you're looking for any collaborators on this project I'd be willing to throw in my hat. I'm extremely interested in a rock solid process launching library based around trio not only because I have a project based on this but also because I think a resilient process spawner is something the Python community needs in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions