Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
goodboy opened this issue Feb 14, 2020 · 2 comments
Closed

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

goodboy opened this issue Feb 14, 2020 · 2 comments

Comments

@goodboy
Copy link

goodboy commented Feb 14, 2020

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.

goodboy added a commit to goodboy/trio-run-in-process that referenced this issue Feb 14, 2020
Control-C and/or signalling with SIGINT doesn't result in clean
cancellation and teardown of a program that has spawned subproceses.
These tests demonstrate this issue as is documented in
ethereum#4.
goodboy added a commit to goodboy/trio-run-in-process that referenced this issue Feb 17, 2020
Control-C and/or signalling with SIGINT doesn't result in clean
cancellation and teardown of a program that has spawned subproceses.
These tests demonstrate this issue as is documented in
ethereum#4.
@gsalgado
Copy link
Contributor

gsalgado commented Jan 6, 2021

I believe this has been fixed in one of my recent commits. Now, if I Ctrl-C the following script

trio.run(run_in_process, trio.sleep_forever)

I get this immediately:

^CTraceback (most recent call last):
  File "issue.py", line 5, in <module>
    trio.run(run_in_process, trio.sleep_forever)
  File "/home/salgado/virtualenvs/trio-rip/lib/python3.8/site-packages/trio/_core/_run.py", line 1896, in run
    raise runner.main_task_outcome.error
  File "/home/salgado/src/snakecharmers/trio-run-in-process/trio_run_in_process/run_in_process.py", line 125, in run_in_process
    return proc.get_result_or_raise()
  File "/home/salgado/src/snakecharmers/trio-run-in-process/trio_run_in_process/process.py", line 161, in get_result_or_raise
    raise self._error
trio.MultiError: KeyboardInterrupt(), KeyboardInterrupt()

Details of embedded exception 1:

  KeyboardInterrupt

Details of embedded exception 2:

  KeyboardInterrupt

@gsalgado gsalgado closed this as completed Jan 6, 2021
@goodboy
Copy link
Author

goodboy commented Jan 17, 2021

@gsalgado why don't you just prove it by merging the test in #5?

Also, what's with the necro-bump of this repo?

Aren't y'all doubling down on https://github.com/ethereum/aio-run-in-process ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants