简体   繁体   中英

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

I am using jupyter notebook.

I have this two files with two scripts: script1.py and 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.

This is what I have so far: A script that runs script1.py every minute in a loop with one minute sleep time.

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?

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:

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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