Search code examples
pythonazurejupyterschedule

Scheduled execution of Python script on Azure


I currently have a free Azure Notebook account on https://notebooks.azure.com/ and would like to execute a Python script (or Jupyter Notebook) hosted on Azure automatically once every 10 minutes.

Is there a way to do this within the free Azure notebook account?

I am aware of several approaches which are described on the web, such as using Azure WebJobs, Azure Functions, Azure IoT and so on. However, all these approaches require me to upgrade to the the "Free" account which actually is only free for the first 12 months, so I would like to avoid that if possible.


Solution

  • As I known, there is not any feature about job like WebJobs for Azure WebApp or Jobs for Azure Databricks in Microsoft Azure Notebooks. So I tried to trigger a Python script via crontab on Ubuntu of Azure Notebooks, but failed because the cron service default not started and Azure does not offer the nbuser password for using sudo to start cron service.

    However, I also tried to write a Python script hello.py as below.

    from datetime import datetime
    import time
    while(True):
        print(f"{datetime.now()} => Hello, world! ")
        time.sleep(10) // 10 seconds
    

    And I ran it in Terminal of Azure Notebooks, as the figures below, then I closed the terminal page and ran !tail -f ~/hello.log, it seems not to be terminated by the closed event of terminal page.

    enter image description here

    enter image description here

    You can try to this way. If it's not what you want, I think it's impossible on Azure Notebooks.