timeouts, etc.

This commit is contained in:
~d6 2024-01-23 10:51:53 -05:00
parent c962f31f15
commit 224acb4461
2 changed files with 11 additions and 7 deletions

View File

@ -38,7 +38,7 @@ priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$')
ignored = {b'rst', b'wst', b''}
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')]
interesting = [s for s in lines if s not in ignored]
result = b' | '.join(interesting)

View File

@ -44,20 +44,24 @@ template = '''
def write_rom(path, s):
f = open(path, 'w')
prog = template % s.decode('utf-8')
prog = template % s
f.write(prog)
f.close()
def execute(s, sandbox=None):
def execute(s, sandbox=None, timeout=2.0):
_, tmp_tal = mkstemp(suffix='.tal', prefix='uxnrepl')
_, tmp_rom = mkstemp(suffix='.rom', prefix='uxnrepl')
write_rom(tmp_tal, s)
res = run(['uxnasm', tmp_tal, tmp_rom], cwd=sandbox, capture_output=True)
##print('*** uxnasm.res is %r' % res)
try:
res = run(['uxnasm', tmp_tal, tmp_rom], cwd=sandbox, capture_output=True, timeout=timeout)
except TimeoutExpired:
return 'uxnasm: timed out'
if res.returncode != 0:
return res.stderr
res = run(['uxncli', tmp_rom], cwd=sandbox, capture_output=True)
##print('*** uxncli.res is %r' % res)
try:
res = run(['uxncli', tmp_rom], cwd=sandbox, capture_output=True, timeout=timeout)
except TimeoutExpired:
return 'uxncli: timed out'
return res.stdout
def main():