some sal edits

This commit is contained in:
Anthony Scopatz 2019-10-04 17:54:06 -04:00
parent 50155c66e3
commit 6b73934857
3 changed files with 66 additions and 4 deletions

View file

@ -361,7 +361,9 @@ def _redirect_streams(r, loc=None):
def default_signal_pauser(n, f):
"""Pauses a signal, as needed."""
print("got hree")
signal.pause()
print("got hbere")
def no_pg_xonsh_preexec_fn():
@ -369,7 +371,9 @@ def no_pg_xonsh_preexec_fn():
pipeline group.
"""
os.setpgrp()
print("running first")
signal.signal(signal.SIGTSTP, default_signal_pauser)
print("running first", 2)
class SubprocSpec:
@ -594,14 +598,17 @@ class SubprocSpec:
if pipeline_group is None or ON_WSL:
# If there is no pipeline group
# or the platform is windows subsystem for linux (WSL)
print("don't have pipeline group")
xonsh_preexec_fn = no_pg_xonsh_preexec_fn
else:
print("have pipeline group")
def xonsh_preexec_fn():
"""Preexec function bound to a pipeline group."""
os.setpgid(0, pipeline_group)
signal.signal(signal.SIGTSTP, default_signal_pauser)
signal.signal(signal.SIGTSTP, default_signal_pauser)
kwargs["preexec_fn"] = xonsh_preexec_fn
def _fix_null_cmd_bytes(self):

View file

@ -202,7 +202,7 @@ else:
last_task=active_task, backgrounded=backgrounded
)
if os.WIFSTOPPED(wcode):
print("^Z")
print("YASS^Z")
active_task["status"] = "stopped"
backgrounded = True
elif os.WIFSIGNALED(wcode):

View file

@ -579,8 +579,9 @@ class PopenThread(threading.Thread):
os.set_inheritable(stdout.fileno(), False)
try:
self.proc = proc = subprocess.Popen(
*args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs
args0 = [sys.executable, "-c", "import subprocess; subprocess.run({!r})".format(args[0])]
self.proc = proc = subprocess.Popen(args0,
*args[1:], stdin=stdin, stdout=stdout, stderr=stderr, **kwargs
)
except Exception:
self._clean_up()
@ -614,7 +615,8 @@ class PopenThread(threading.Thread):
stdin = self.stdin
if self.orig_stdin is None:
origin = None
elif ON_POSIX and self.store_stdin:
#elif ON_POSIX and self.store_stdin:
elif ON_POSIX:
origin = self.orig_stdin
origfd = origin if isinstance(origin, int) else origin.fileno()
origin = BufferedFDParallelReader(origfd, buffer=stdin)
@ -699,6 +701,10 @@ class PopenThread(threading.Thread):
i = -1
for i, chunk in enumerate(iter(reader.read_queue, b"")):
self._alt_mode_switch(chunk, writer, stdbuf)
if b"^Z" in chunk or b"\x1a" in chunk:
self._alt_mode_writer(b"^Z was pressed OMG", writer, stdbuf)
reader.closed = True
break
if i >= 0:
writer.flush()
stdbuf.flush()
@ -808,9 +814,13 @@ class PopenThread(threading.Thread):
def _signal_tstp(self, signum, frame):
"""Signal handler for suspending SIGTSTP - Ctrl+Z may have been pressed.
"""
print("SIGTSTP", 1)
self.suspended = True
print("SIGTSTP", 2)
self.send_signal(signum)
print("SIGTSTP", 3)
self._restore_sigtstp(frame=frame)
print("SIGTSTP", 4)
def _restore_sigtstp(self, frame=None):
old = self.old_tstp_handler
@ -1749,6 +1759,7 @@ def SIGNAL_MESSAGES():
signal.SIGILL: "Illegal instructions",
signal.SIGTERM: "Terminated",
signal.SIGSEGV: "Segmentation fault",
signal.SIGTSTP: "Stopped",
}
if ON_POSIX:
sm.update(
@ -1846,9 +1857,11 @@ class CommandPipeline:
self.lines = []
self._stderr_prefix = self._stderr_postfix = None
self.term_pgid = None
self._tc_cc_susp = None
background = self.spec.background
pipeline_group = None
self._disable_suspend_signal()
for spec in specs:
if self.starttime is None:
self.starttime = time.time()
@ -2149,6 +2162,7 @@ class CommandPipeline:
# ^Z event. This *has* to be called after we give the terminal
# back to the shell.
builtins.__xonsh__.shell.shell.restore_tty_sanity()
self._restore_suspend_signal()
def resume(self, job, tee_output=True):
self.ended = False
@ -2264,6 +2278,47 @@ class CommandPipeline:
# this is need to get a working terminal in interactive mode
self._return_terminal()
def _disable_suspend_signal(self):
if ON_WINDOWS:
return
#stty, _ = builtins.__xonsh__.commands_cache.lazyget("stty", (None, None))
#if stty is None:
# return
#os.system(stty + " sane -isig")
#os.system(stty + " sane susp undef swtch ^Z")
#os.system(stty + " sane susp undef dsusp ^Z")
#os.system(stty + " -a")
#return
mode = termios.tcgetattr(0) # only makes sense for stdin
self._tc_cc_susp = mode[CC][termios.VSUSP]
#new_cc = self._tcmode[CC][:]
#new_cc[termios.VSUSP] = b'\x00' # set ^Z (ie SIGSTOP) to undefined
#mode[CC][termios.VSUSP] = b'\x00' # set ^Z (ie SIGSTOP) to undefined
#mode[LFLAG] &= ~termios.ECHOCTL
#new_mode = self._tcmode[:]
#new_mode[CC] = new_cc
termios.tcsetattr(0, termios.TCSANOW, mode)
def _restore_suspend_signal(self):
if ON_WINDOWS:
return
#stty, _ = builtins.__xonsh__.commands_cache.lazyget("stty", (None, None))
#if stty is None:
# return
#os.system(stty + " sane")
#os.system(stty + " -a")
#return
mode = termios.tcgetattr(0) # only makes sense for stdin
#mode[CC][termios.VSUSP] = self._tc_cc_susp # set ^Z (ie SIGSTOP) to undefined
mode[CC][termios.VSUSP] = b"\x1a" # set ^Z (ie SIGSTOP) to undefined
#mode[LFLAG] |= termios.ECHOCTL
print(self._tc_cc_susp)
try:
termios.tcsetattr(0, termios.TCSANOW, mode)
except termios.error:
pass
#
# Properties
#