繁体   English   中英

在jupyter笔记本中一个接一个地运行两个file.py

[英]run two file.py one after the other in jupyter notebook

我正在使用jupyter笔记本。

我有两个带有两个脚本的文件:script1.py和script2.py

虽然文件script1.py在while循环中每分钟运行一次,但我想在同一循环中运行script.1后4分钟运行script2.py。

这就是我到目前为止所拥有的:一个脚本,该脚本每分钟在一个循环中运行script1.py,睡眠时间为一分钟。

starttime=time.time()

while True:
     %run "script1.py"
     time.sleep(60.0 - ((time.time() - starttime) % 60.0))

在哪里可以将%run“ script2.py”添加到此代码中?

也许你可以做类似的事情

starttime= time.time()

while True:
    %run "script1.py"
    time.sleep(60.0 - ((time.time() - starttime) % 60.0))
    if( (starttime - time.time()) > 240): %run "script2.py"

只需检查是否已经过了4分钟,然后运行script2即可:

starttime=time.time()

 while True:
     %run "script1.py"

     if (time.time() - starttime) >= 240.0
         %run "script2.py"

     time.sleep(60.0 - ((time.time() - starttime) % 60.0))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM