[英]run two file.py one after the other in jupyter notebook
I am using jupyter notebook. 我正在使用jupyter笔记本。
I have this two files with two scripts: script1.py and script2.py 我有两个带有两个脚本的文件:script1.py和script2.py
While file script1.py runs every minutes in a while loop, I would like to run script2.py 4 minutes after running script.1, in the same loop. 虽然文件script1.py在while循环中每分钟运行一次,但我想在同一循环中运行script.1后4分钟运行script2.py。
This is what I have so far: A script that runs script1.py every minute in a loop with one minute sleep time. 这就是我到目前为止所拥有的:一个脚本,该脚本每分钟在一个循环中运行script1.py,睡眠时间为一分钟。
starttime=time.time()
while True:
%run "script1.py"
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
Where can I add %run "script2.py" to this code? 在哪里可以将%run“ script2.py”添加到此代码中?
perhaps you could do something like 也许你可以做类似的事情
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"
Just check if it's been 4 minutes, and run script2 if it has: 只需检查是否已经过了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.