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

on Ctrl-C -- kill child not itself #184

Open
yarikoptic opened this issue Sep 20, 2024 · 2 comments
Open

on Ctrl-C -- kill child not itself #184

yarikoptic opened this issue Sep 20, 2024 · 2 comments
Assignees

Comments

@yarikoptic
Copy link
Member

Currently

❯ duct  dd if=/dev/zero of=/dev/null
2024-09-20T10:26:35-0400 [INFO    ] con-duct: duct is executing 'dd if=/dev/zero of=/dev/null'...
2024-09-20T10:26:35-0400 [INFO    ] con-duct: Log files will be written to .duct/logs/2024.09.20T10.26.35-184161_
^C^C^CTraceback (most recent call last):
  File "/usr/lib/python3.12/subprocess.py", line 1264, in wait
    return self._wait(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 2053, in _wait
    (pid, sts) = self._try_wait(0)
                 ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 2011, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yoh/proj/CON/duct/venvs/dev3.12/bin/duct", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/yoh/proj/CON/duct/src/con_duct/__main__.py", line 883, in main
    sys.exit(execute(args))
             ^^^^^^^^^^^^^
  File "/home/yoh/proj/CON/duct/src/con_duct/__main__.py", line 972, in execute
    process.wait()
  File "/usr/lib/python3.12/subprocess.py", line 1277, in wait
    self._wait(timeout=sigint_timeout)
  File "/usr/lib/python3.12/subprocess.py", line 2047, in _wait
    time.sleep(delay)
KeyboardInterrupt
^CException ignored in: <module 'threading' from '/usr/lib/python3.12/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1624, in _shutdown
    lock.acquire()
KeyboardInterrupt: 

so we are pretty much killing ourselves and do not provide summary etc. I think we should

  • intercept Ctrl-C (I think it is possible, offlineimap does it) and unless 3 times consecutive within e.g. 3 seconds, we instead "peacefully" killing the underlying child process instead and "proceed" normally printing its killed exit code and summary
@asmacdo
Copy link
Member

asmacdo commented Sep 20, 2024

+100

@asmacdo asmacdo self-assigned this Sep 20, 2024
@asmacdo
Copy link
Member

asmacdo commented Sep 30, 2024

offlineimap does this using sig_handlers https://github.com/OfflineIMAP/offlineimap3/blob/db347452273bb0f1b1a8ea952f6fb46cf95fedbf/offlineimap/init.py#L482
and events https://github.com/OfflineIMAP/offlineimap3/blob/db347452273bb0f1b1a8ea952f6fb46cf95fedbf/offlineimap/accounts.py#L452

That general approach should work for us also.

I propose this interface:

  • First SIGTERM: send SIGTERM to the parent process that duct is executing
  • Second SIGTERM: send SIGKILL to the parent process that duct is executing
  • Third SIGTERM: immediately exit, even if we are leaving the process running

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