def wait_for_active_job(signal_to_send=None):
"""
Wait for the active job to finish, to be killed by SIGINT, or to be
suspended by ctrl-z.
"""
_clear_dead_jobs()
act = builtins.__xonsh_active_job__
if act is None:
return
job = builtins.__xonsh_all_jobs__[act]
obj = job['obj']
if job['bg']:
return
pgrp = job['pgrp']
obj.done = False
# give the terminal over to the fg process
_give_terminal_to(pgrp)
# if necessary, send the specified signal to this process
# (this hook was added because vim, emacs, etc, seem to need to have
# the terminal when they receive SIGCONT from the "fg" command)
if signal_to_send is not None:
os.kill(obj.pid, signal_to_send)
_, 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
评论列表
文章目录