23
def timeout(signum, frame):
24
print 'signal: ', signum
25
raise Exception, 'Timeout!'
27
signal.signal(signal.SIGALRM, timeout)
29
sok = socket.socket(socket.AF_INET)
30
sok.bind(('localhost',9998))
32
(new_sok,addr) = sok.accept()
34
c = codeop.CommandCompiler()
38
globs['__builtins__'] = globals()['__builtins__']
40
out = cStringIO.StringIO()
43
for line in req_lines(new_sok):
48
src = src + '\n' + line
52
res = eval(cmd, globs, locos)
54
new_sok.send(cjson.encode((out.getvalue(),res)) + '\n')
55
out = cStringIO.StringIO()
59
sok.shutdown(socket.SHUT_RDWR)