bash - capturing keyboard interrupts during while executing Python scripts -


i executing bash script in python using tempfile , subprocess so:

 tempfile.namedtemporaryfile() scriptfile:                 scriptfile.write(teststr)                 scriptfile.flush()                 subprocess.call(['/bin/bash', scriptfile.name]) 

here, teststr has entire bash script within it. question is, once starts execute, doesn't capture keyboard interrupts ctrl+c , ctrl+z.

is there anyway interrupt execution of script once has begun?

i assume problem python parent process receives sigint ctrl+c , quits unhandled exception, child ignores signal , keeps running. scenario able reproduce. actual problem may differ. catching exception , killing subprocess explicitly sigkill may work.

instead of subprocess.call:

proc = subprocess.popen(['/bin/bash', scriptfile.name]) try:     proc.wait() except:     proc.kill()     raise 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -