timeouts, etc.
This commit is contained in:
parent
c962f31f15
commit
224acb4461
|
@ -38,7 +38,7 @@ priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$')
|
||||||
ignored = {b'rst', b'wst', b''}
|
ignored = {b'rst', b'wst', b''}
|
||||||
|
|
||||||
def evaluate(msg):
|
def evaluate(msg):
|
||||||
output = uxnrepl.execute(msg, sandbox=sandbox)
|
output = uxnrepl.execute(msg.decode('utf-8'), sandbox=sandbox)
|
||||||
lines = [s.strip() for s in output.split(b'\n')]
|
lines = [s.strip() for s in output.split(b'\n')]
|
||||||
interesting = [s for s in lines if s not in ignored]
|
interesting = [s for s in lines if s not in ignored]
|
||||||
result = b' | '.join(interesting)
|
result = b' | '.join(interesting)
|
||||||
|
|
16
uxnrepl.py
16
uxnrepl.py
|
@ -44,20 +44,24 @@ template = '''
|
||||||
|
|
||||||
def write_rom(path, s):
|
def write_rom(path, s):
|
||||||
f = open(path, 'w')
|
f = open(path, 'w')
|
||||||
prog = template % s.decode('utf-8')
|
prog = template % s
|
||||||
f.write(prog)
|
f.write(prog)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def execute(s, sandbox=None):
|
def execute(s, sandbox=None, timeout=2.0):
|
||||||
_, tmp_tal = mkstemp(suffix='.tal', prefix='uxnrepl')
|
_, tmp_tal = mkstemp(suffix='.tal', prefix='uxnrepl')
|
||||||
_, tmp_rom = mkstemp(suffix='.rom', prefix='uxnrepl')
|
_, tmp_rom = mkstemp(suffix='.rom', prefix='uxnrepl')
|
||||||
write_rom(tmp_tal, s)
|
write_rom(tmp_tal, s)
|
||||||
res = run(['uxnasm', tmp_tal, tmp_rom], cwd=sandbox, capture_output=True)
|
try:
|
||||||
##print('*** uxnasm.res is %r' % res)
|
res = run(['uxnasm', tmp_tal, tmp_rom], cwd=sandbox, capture_output=True, timeout=timeout)
|
||||||
|
except TimeoutExpired:
|
||||||
|
return 'uxnasm: timed out'
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
return res.stderr
|
return res.stderr
|
||||||
res = run(['uxncli', tmp_rom], cwd=sandbox, capture_output=True)
|
try:
|
||||||
##print('*** uxncli.res is %r' % res)
|
res = run(['uxncli', tmp_rom], cwd=sandbox, capture_output=True, timeout=timeout)
|
||||||
|
except TimeoutExpired:
|
||||||
|
return 'uxncli: timed out'
|
||||||
return res.stdout
|
return res.stdout
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue