jupyter notebook使用.py运行,报错 timeouterror cell execution timed out


# 默认一个cell30s,实际几个cell远超30s
https://juejin.cn/s/jupyter%20timeouterror%20cell%20execution%20timed%20out
# 1.增加超时时间:在Notebook中添加以下代码,可以将超时时间延长到更长的时间。例如,以下代码将超时时间设置为60秒。
# 2.优化代码:如果您的代码确实需要很长时间才能执行完毕,那么您可以尝试优化代码,使其更快执行。例如,使用更高效的算法或数据结构,避免使用嵌套循环等。
# 3.分割代码:如果您的代码太长,可以尝试将其分成多个部分并逐个执行,这样就可以避免超时的问题。

Preventing Jupyter timeout errors when running notebooks as a batch/scheduled job

https://github.com/executablebooks/jupyter-book/issues/613

https://github.com/executablebooks/jupyter-book/issues/945

https://github.com/executablebooks/jupyter-cache/issues/39

https://github.com/ipython/ipython/issues/8382

# The timeout is configurable. 
# Set c.ExecutePreprocessor.timeout in the config file, 
# or pass --ExecutePreprocessor.timeout=180 at the command line.


# import signal
# from contextlib import contextmanager

# @contextmanager
# def time_limit(seconds):
#     def signal_handler(signum, frame):
#         raise TimeoutError("Time's up!")
    
#     signal.signal(signal.SIGALRM, signal_handler)
#     signal.alarm(seconds)

#     try:
#         yield
#     finally:
#         signal.alarm(0)
        
# %%time
# with time_limit(300):
#     time.sleep(20)
#     # your code here
 

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值