def run_subprocess(cinput, invoke, universal_newlines=True, **kwargs):
process = subprocess.Popen(invoke, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=universal_newlines, **kwargs)
try:
result = process.communicate(input=cinput, timeout=60)[0]
except subprocess.TimeoutExpired:
process.kill()
result = "Sorry, your code took too long to run!"
partial_out = process.communicate()[0] # communicate returns a tuple first element is stdout second is stderr
if partial_out:
result += "\nPartial output:\n" + partial_out
except:
traceback.print_exc()
result = "There was an issue running your code."
return result
#temporary workaround while TIO is bugged
评论列表
文章目录