From de7665b6964f2301c76747ea16732d4d4a337b81 Mon Sep 17 00:00:00 2001 From: adam j hartz Date: Sun, 29 Mar 2015 10:03:39 -0400 Subject: [PATCH] avoid polling and time delay when waiting for current job to stop --- xonsh/jobs.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/xonsh/jobs.py b/xonsh/jobs.py index 08b0688d8..6f22f2e4c 100644 --- a/xonsh/jobs.py +++ b/xonsh/jobs.py @@ -103,22 +103,15 @@ def wait_for_active_job(): obj.done = False _give_terminal_to(pgrp) # give the terminal over to the fg process - while True: - p, s = os.waitpid(obj.pid, os.WNOHANG | os.WUNTRACED) - if p == obj.pid: - if os.WIFSTOPPED(s): - obj.done = True - job['bg'] = True - job['status'] = 'stopped' - print() # get a newline because ^Z will have been printed - print_one_job(act) - break - elif os.WIFSIGNALED(s): - print() # get a newline because ^C will have been printed - break - elif os.WIFEXITED(s): - break - time.sleep(0.1) + p, s = os.waitpid(obj.pid, os.WUNTRACED) + if os.WIFSTOPPED(s): + obj.done = True + job['bg'] = True + job['status'] = 'stopped' + print() # get a newline because ^Z will have been printed + print_one_job(act) + elif os.WIFSIGNALED(s): + print() # get a newline because ^C will have been printed if obj.poll() is not None: builtins.__xonsh_active_job__ = None _give_terminal_to(_shell_pgrp) # give terminal back to the shell