Hello,
I have the following small script that just spawns a subprocess which periodically writes the date to a file.
import subprocess import time def main(): subprocess.Popen("while true; do date > hello.txt; sleep 1; done", shell=True) while True: time.sleep(1) if __name__ == "__main__": main()
I run the script from inside my terminal with python3 my_script.py
and it does as expected. Now when I press CTRL+C it does the keyboard interrupt and the script terminates and the subprocess terminates as well which can be seen as the file not being written to anymore. But when I terminate the script by sending a SIGTERM to its process, the subprocess keeps running. Why is that? How does python handle the subprocess when it comes to terminating it?
submitted by /u/throwaway-0xDEADBEEF
[link] [comments]
r/learnpython Hello, I have the following small script that just spawns a subprocess which periodically writes the date to a file. import subprocess import time def main(): subprocess.Popen(“while true; do date > hello.txt; sleep 1; done”, shell=True) while True: time.sleep(1) if __name__ == “__main__”: main() I run the script from inside my terminal with python3 my_script.py and it does as expected. Now when I press CTRL+C it does the keyboard interrupt and the script terminates and the subprocess terminates as well which can be seen as the file not being written to anymore. But when I terminate the script by sending a SIGTERM to its process, the subprocess keeps running. Why is that? How does python handle the subprocess when it comes to terminating it? submitted by /u/throwaway-0xDEADBEEF [link] [comments]
Hello,
I have the following small script that just spawns a subprocess which periodically writes the date to a file.
import subprocess import time def main(): subprocess.Popen("while true; do date > hello.txt; sleep 1; done", shell=True) while True: time.sleep(1) if __name__ == "__main__": main()
I run the script from inside my terminal with python3 my_script.py
and it does as expected. Now when I press CTRL+C it does the keyboard interrupt and the script terminates and the subprocess terminates as well which can be seen as the file not being written to anymore. But when I terminate the script by sending a SIGTERM to its process, the subprocess keeps running. Why is that? How does python handle the subprocess when it comes to terminating it?
submitted by /u/throwaway-0xDEADBEEF
[link] [comments]