From b093112f2fd42280ae1b2a7a34e03779e85fc57a Mon Sep 17 00:00:00 2001 From: Colombo Date: Sat, 29 Feb 2020 15:39:43 +0400 Subject: [PATCH] _ --- core/interact/interact.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/core/interact/interact.py b/core/interact/interact.py index 022c987..d6265d7 100644 --- a/core/interact/interact.py +++ b/core/interact/interact.py @@ -363,6 +363,25 @@ class InteractBase(object): sq.put (True) except: sq.put (False) + + outnull_file = open(os.devnull, 'w') + errnull_file = open(os.devnull, 'w') + + old_stdout_fileno_undup = sys.stdout.fileno() + old_stderr_fileno_undup = sys.stderr.fileno() + + old_stdout_fileno = os.dup ( sys.stdout.fileno() ) + old_stderr_fileno = os.dup ( sys.stderr.fileno() ) + + old_stdout = sys.stdout + old_stderr = sys.stderr + + os.dup2 ( outnull_file.fileno(), old_stdout_fileno_undup ) + os.dup2 ( errnull_file.fileno(), old_stderr_fileno_undup ) + + sys.stdout = outnull_file + sys.stderr = errnull_file + def input_in_time (self, str, max_time_sec): sq = multiprocessing.Queue() @@ -378,10 +397,10 @@ class InteractBase(object): if time.time() - t > max_time_sec: break - print("1") + p.terminate() p.join() - print("2") + old_stdin = sys.stdin sys.stdin = os.fdopen( os.dup(sys.stdin.fileno()) ) old_stdin.close()