Running google colab every day at a specific time
Asked Answered
S

5

39

I recently have built a Python program that runs on Google Colaboratory, I need to run the program every day at a specific time, So Is there any way to schedule it to run on Google Colab?

Smetana answered 12/5, 2020 at 21:13 Comment(2)
Having the same question, and all answers did not satisfy me enoughKerato
--looking for a better solutionMonge
C
21

You need to create a notebooks.csv listing all the Colaboratory URLs. Then use colabctl to run each notebook (In order, synchronously mentioned in the CSV) and then pauses for a period of n seconds of time before running them again.

You can then run python colabctl.py <end-string> <sleep-seconds>,

There's a gCookies.pkl file in the repo. Ensure that your local Python version is the same one as used to create this serialized pkl file.

Ref: https://github.com/TensorTom/colabctl

Now that we have a notebook and script ready, next is to be able to SSH into Google colab.

  • create an account on ngrok.com
  • Copy and paste below code in colab which installs ngrok and creates a tunnel for us

Source : https://gist.github.com/yashkumaratri/204755a85977586cebbb58dc971496da#file-google-colab-ssh

  • Now, on your local machine, open terminal and SSH to connect to the Colab System.

ssh [email protected] -p <port_num_generated_above>

Now you have access to the whole system through SSH terminal. And can continue to use colabctl to any other corn script on local environment to execute your remote colab script.

Corny answered 12/6, 2020 at 19:24 Comment(3)
I'm looking for a way to run it on Google Colab on a schedule. Not how to run it on my local python installation.Mathers
@Mathers Check the updated description. Let me know if you get stuck somewhere.Corny
Scheduling Colabs seems to now be natively supported (if you are willing to pay): github.com/googlecolab/colabtools/wiki/Scheduled-notebooksRussophobe
M
9

If you are willing to pay for this, you can use the Google Cloud scheduler:

https://cloud.google.com/scheduler

Related links for setup details:

https://minimaxir.com/2018/11/cheap-cron/

https://cloud.google.com/scheduler/docs/quickstart

If not, in addition to the previous answer, you can consider moving the script to your local environment and using Task Scheduler.

Maxi answered 8/6, 2020 at 7:17 Comment(0)
L
3

You can use colabctl to run your Google Colaboratory notebooks from the command line, on a schedule if you wish. Simply add colabctl.py to a cron job.

Note: If you want to run it on a headless server, you will first need to run it once from your desktop to save your login cookie to the pickle file and then upload that pickle to your server along with colabctl.

Leap answered 5/6, 2020 at 22:58 Comment(2)
I'm looking for a way to run it on Google Colab on a schedule. Not how to run it on my local python installation.Mathers
I think Google is nice enough to spare some valuable server time, don't milk the cow dead. The solution is to get a free tier on the Google Cloud Platform.Leap
R
3

Scheduling scripts seems to now be natively supported in Google Colab (if you are willing to pay): https://github.com/googlecolab/colabtools/wiki/Scheduled-notebooks

Russophobe answered 1/4, 2023 at 11:10 Comment(1)
Are you 100% sure about this @nullstellensatz? It doesn't seem to be described as a feature: colab.research.google.com/signupHesitant
H
1

You can use DeepNote, even the free plan allows to schedule your scripts.

Halves answered 4/11, 2022 at 11:47 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Shamus
This is not the case anymoreOstiole

© 2022 - 2024 — McMap. All rights reserved.