def loop(interactive): histfile = os.path.expanduser("~/.polysh_history") init_history(histfile) next_signal = None last_status = None while True: try: if next_signal: current_signal = next_signal next_signal = None sig2chr = {signal.SIGINT: 'C', signal.SIGTSTP: 'Z'} ctrl = sig2chr[current_signal] remote_dispatcher.log('> ^{}\n'.format(ctrl).encode()) control_commands.do_send_ctrl(ctrl) console_output(b'') stdin.the_stdin_thread.prepend_text = None while dispatchers.count_awaited_processes()[0] and \ remote_dispatcher.main_loop_iteration(timeout=0.2): pass # Now it's quiet for r in dispatchers.all_instances(): r.print_unfinished_line() current_status = dispatchers.count_awaited_processes() if current_status != last_status: console_output(b'') if remote_dispatcher.options.interactive: stdin.the_stdin_thread.want_raw_input() last_status = current_status if dispatchers.all_terminated(): # Clear the prompt console_output(b'') raise asyncore.ExitNow(remote_dispatcher.options.exit_code) if not next_signal: # possible race here with the signal handler remote_dispatcher.main_loop_iteration() except KeyboardInterrupt: if interactive: next_signal = signal.SIGINT else: kill_all() os.kill(0, signal.SIGINT) except asyncore.ExitNow as e: console_output(b'') save_history(histfile) sys.exit(e.args[0])
def want_raw_input(self) -> None: nr, total = dispatchers.count_awaited_processes() if nr: prompt = 'waiting (%d/%d)> ' % (nr, total) else: prompt = 'ready (%d)> ' % total self.prompt = prompt set_last_status_length(len(prompt)) self.raw_input_wanted.set() while not self.in_raw_input.is_set(): self.socket_notification.handle_read() self.in_raw_input.wait(0.1) self.raw_input_wanted.clear()
def want_raw_input(self): nr, total = dispatchers.count_awaited_processes() if nr: prompt = 'waiting (%d/%d)> ' % (nr, total) else: prompt = 'ready (%d)> ' % total self.prompt = prompt set_last_status_length(len(prompt)) self.raw_input_wanted.set() while not self.in_raw_input.isSet(): self.socket_notification.handle_read() self.in_raw_input.wait(0.1) self.raw_input_wanted.clear()
def main_loop(): global next_signal last_status = None while True: try: if next_signal: current_signal = next_signal next_signal = None sig2chr = {signal.SIGINT: 'c', signal.SIGTSTP: 'z'} ctrl = sig2chr[current_signal] remote_dispatcher.log('> ^%c\n' % ctrl.upper()) control_commands.do_send_ctrl(ctrl) console_output('') the_stdin_thread.prepend_text = None while dispatchers.count_awaited_processes()[0] and \ remote_dispatcher.main_loop_iteration(timeout=0.2): pass # Now it's quiet for r in dispatchers.all_instances(): r.print_unfinished_line() current_status = dispatchers.count_awaited_processes() if current_status != last_status: console_output('') if remote_dispatcher.options.interactive: the_stdin_thread.want_raw_input() last_status = current_status if dispatchers.all_terminated(): # Clear the prompt console_output('') raise asyncore.ExitNow(remote_dispatcher.options.exit_code) if not next_signal: # possible race here with the signal handler remote_dispatcher.main_loop_iteration() except asyncore.ExitNow, e: console_output('') sys.exit(e.args[0])