

doza_and
1 Приведите код как вы это делаете.2. можно попробовать жестче поступить. У результата popen есть метод kill()
prc = subprocess.Popen(prog, stdin=subprocess.PIPE, stdout=stream) pid = prc.pid while psutil.pid_exists(pid): if time> time_allowed and signaled == False: prc.send_signal(signal.CTRL_C_EVENT) prc.stdin.write('Y\n'.encode()) signaled = True time.sleep(1) time= time+ 1
import time def main(): counter = 0 while True: try: print(counter) counter += 1 time.sleep(1) except KeyboardInterrupt: s = input('Are you sure? Y/N') if s == 'Y': print('Good Bye') break if __name__ == '__main__': main()
import subprocess import time import signal sp = subprocess.Popen(['python3', 'py_main.py'], stdin=subprocess.PIPE) time.sleep(3) sp.send_signal(signal.SIGINT) time.sleep(0.25) sp.stdin.write('Y\n'.encode())