I am trying to write a helper script to shorten some of my project commands.
The script looks like this:
import subprocess
def up():
subprocess.call(['docker-compose', 'up'])
if __name__ == '__main__':
up()
This works, however if I run ctrl + c
, it will kill the script and not the subprocess.
Is there a way I can make the subprocess
the priority for all terminal input until it exits?
I solved this as follows:
def up():
try:
subprocess.call(['docker-compose', 'up'])
except KeyboardInterrupt:
print('\n')
It appears to do the job.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.