首页IT科技python中的super(python函数超时怎么自动退出?)

python中的super(python函数超时怎么自动退出?)

时间2025-05-04 22:46:12分类IT科技浏览3429
导读:本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。...

本文教程操作环境:windows7系统         、Python 3.9.1            ,DELL G3电脑         。

安装timeout-decorator库:

pip3installtimeout-decorator

编写异常语句:

@timeout_decorator.timeout(5,timeout_exception=StopIteration)

函数限制超时:

@timeout_decorator.timeout(5,use_signals=False)

解决案例:

importtimeout_decorator @timeout_decorator.timeout(5) defmytest(): print("Start") foriinrange(1,10): time.sleep(1) print("{}secondshavepassed".format(i)) defmain(): mytest() if__name__==__main__: main()

《相关推荐:php框架》

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
玩游戏赚钱的平台排行榜(有什么玩游戏赚钱的平台么-正规游戏**平台有哪些?如何找到它?) 宁国论坛关注宁国新闻(宁国论坛一一关注宁国下载)