Skip to content

Commit

Permalink
Ignore SIGTERM/SIGINT in Python child process.
Browse files Browse the repository at this point in the history
This fixes a race condition between the application under test exiting (with
exit code 0) and the Python subprocess running it exiting with exit code -SIG.
  • Loading branch information
adamshapiro0 committed Apr 14, 2021
1 parent 5208ad9 commit 0b6f063
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions c/test/application_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ def run(self, return_result=False):
command[i] = command[i].replace(api_key_standin, self.options.polaris_api_key)

# Run the command.
def ignore_signal(sig, frame):
signal.signal(sig, signal.SIG_DFL)

def preexec_function():
# Disable forwarding of SIGINT/SIGTERM from the parent process (this script) to the child process (the
# application under test).
os.setpgrp()
signal.signal(signal.SIGINT, ignore_signal)
signal.signal(signal.SIGTERM, ignore_signal)

self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8',
preexec_fn=preexec_function)
Expand Down

0 comments on commit 0b6f063

Please sign in to comment.