-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.py
More file actions
47 lines (41 loc) · 1.36 KB
/
Console.py
File metadata and controls
47 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import threading
class Console(object):
def __init__(self, oInterpret):
self.oInterpret = oInterpret
'''
Fork every input.
'''
def console(self, communication_Event):
forked_Event = threading.Event()
forked_Event.set()
while communication_Event.is_set():
try:
line = raw_input()
thread = threading.Thread(target = self.inputOperator, name = 'forked_console',
args = (line, forked_Event,))
thread.daemon = True
thread.start()
except (KeyboardInterrupt, EOFError):
print "Closing all threads..."
communication_Event.clear()
'''
Interprets input and prints the result.
'''
def inputOperator(self, line, forked_Event):
res = self.oInterpret.interpret(line)
if res == None:
return
try:
if forked_Event.is_set():
print res
except KeyboardInterrupt:
print "KeyboardInterrupt exception."
forked_Event.clear()
if __name__ == '__main__':
import Interpret
print "Testing Console..."
oInterpret = Interpret.Interpret()
oConsole = Console(oInterpret)
print "Objects created."
oConsole.console()
print "Successful launch."