Send a SIGINT to the process similar to if +C were pressed.
(self)
| 543 | self._err_thread.start() |
| 544 | |
| 545 | def send_sigint(self) -> None: |
| 546 | """Send a SIGINT to the process similar to if <Ctrl>+C were pressed.""" |
| 547 | import signal |
| 548 | |
| 549 | if sys.platform.startswith("win"): |
| 550 | # cmd2 started the Windows process in a new process group. Therefore we must send |
| 551 | # a CTRL_BREAK_EVENT since CTRL_C_EVENT signals cannot be generated for process groups. |
| 552 | self._proc.send_signal(signal.CTRL_BREAK_EVENT) |
| 553 | else: |
| 554 | # Since cmd2 uses shell=True in its Popen calls, we need to send the SIGINT to |
| 555 | # the whole process group to make sure it propagates further than the shell |
| 556 | try: |
| 557 | group_id = os.getpgid(self._proc.pid) |
| 558 | os.killpg(group_id, signal.SIGINT) |
| 559 | except ProcessLookupError: |
| 560 | return |
| 561 | |
| 562 | def terminate(self) -> None: |
| 563 | """Terminate the process.""" |
no outgoing calls