EvalModule.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:DataBot 作者: Mego 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号