Skip to content

Commit

Permalink
Remove preexec_fn from subprocess call in console_io.py
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 304646913
Change-Id: I16b76e90490984fd9f751823bf1304d75eb087a0
  • Loading branch information
dbieber committed Apr 3, 2020
1 parent 61785e6 commit af9d848
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions fire/console/console_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ def IsInteractive(output=False, error=False, heuristic=False):
return True


def PreexecFunc():
signal.signal(signal.SIGINT, signal.SIG_IGN)


def More(contents, out, prompt=None, check_pager=True):
"""Run a user specified pager or fall back to the internal pager.
Expand Down Expand Up @@ -102,18 +98,14 @@ def More(contents, out, prompt=None, check_pager=True):
less_orig = encoding.GetEncodedValue(os.environ, 'LESS', None)
less = '-R' + (less_orig or '')
encoding.SetEncodedValue(os.environ, 'LESS', less)
# Ignores SIGINT from this point on since the child process has started
# and we don't want to terminate either one when the child is still alive.
# Ignore SIGINT while the pager is running.
# We don't want to terminate the parent while the child is still alive.
signal.signal(signal.SIGINT, signal.SIG_IGN)
# Runs PreexecFunc before starting the child so SIGINT is ignored for the
# child process as well.
p = subprocess.Popen(
pager, stdin=subprocess.PIPE, shell=True, preexec_fn=PreexecFunc)
p = subprocess.Popen(pager, stdin=subprocess.PIPE, shell=True)
enc = console_attr.GetConsoleAttr().GetEncoding()
p.communicate(input=contents.encode(enc))
p.wait()
# Starts using default disposition for SIGINT again after the child has
# exited.
# Start using default signal handling for SIGINT again.
signal.signal(signal.SIGINT, signal.SIG_DFL)
if less_orig is None:
encoding.SetEncodedValue(os.environ, 'LESS', None)
Expand Down

0 comments on commit af9d848

Please sign in to comment.