在运行测试系统时克服 python 中的 stackoverflow

问题描述

我编写了一个代码来检查我学生的 Python 代码并将他们的输出与正确的代码进行比较。我为每个代码运行使用 signal 25 秒。然而其中一位学生写了以下有问题的代码

def func(a,b,c,d,e):
    return func(a,e)

信号不会中断这段代码,我的评分代码因堆栈溢出错误而崩溃。目前负责分级的块看起来像

import signal
Is_EXACT = 1
PROXIMITY= 0.1
from tests import right_output
import numpy as np

try:
    try:
        signal.signal(signal.SIGALRM,handler)
        signal.alarm(25)
        import submission
        student_func = getattr(submission,functionname)
        stud_output = student_func(inp[0],inp[1],inp[2],inp[3],inp[4])
    except:
        return 0
    if IS_EXACT:
        np.testing.assert_equal(stud_output,right_output)
        return 1
    else:
        return int(np.abs(stud_output - right_output) < PROXIMITY)
except:
    return 0

除了 signal 之外,我还可以使用什么包来克服他的代码中的无限循环?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...