This commit is contained in:
Colombo
2020-02-29 15:00:46 +04:00
parent 7f609d0f0a
commit 98d3657cbc
+6 -1
View File
@@ -366,7 +366,11 @@ class InteractBase(object):
sq.put (True) sq.put (True)
except: except:
sq.put (False) sq.put (False)
sq.close()
sq = None
import gc
gc.collect()
def input_in_time (self, str, max_time_sec): def input_in_time (self, str, max_time_sec):
sq = multiprocessing.Queue() sq = multiprocessing.Queue()
p = multiprocessing.Process(target=self.input_process, args=( sys.stdin.fileno(), sq, str)) p = multiprocessing.Process(target=self.input_process, args=( sys.stdin.fileno(), sq, str))
@@ -381,6 +385,7 @@ class InteractBase(object):
if time.time() - t > max_time_sec: if time.time() - t > max_time_sec:
break break
p.terminate() p.terminate()
p.join()
sq.close() sq.close()
old_stdin = sys.stdin old_stdin = sys.stdin
sys.stdin = os.fdopen( os.dup(sys.stdin.fileno()) ) sys.stdin = os.fdopen( os.dup(sys.stdin.fileno()) )