简体   繁体   English

在 Azure 上计划执行 Python 脚本

[英]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.我目前在https://notebooks.azure.com/上有一个免费的 Azure Notebook 帐户,并且希望每 10 分钟自动执行一次托管在 Azure 上的 Python 脚本(或 Jupyter Notebook)。

Is there a way to do this within the free Azure notebook account?有没有办法在免费的 Azure 笔记本帐户中做到这一点?

I am aware of several approaches which are described on the web, such as using Azure WebJobs, Azure Functions, Azure IoT and so on.我知道网络上描述的几种方法,例如使用 Azure WebJobs、Azure Functions、Azure IoT 等。 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.但是,所有这些方法都要求我升级到“免费”帐户,该帐户实际上仅在前 12 个月内免费,因此我希望尽可能避免这种情况。

There are a number of 'always free' services that come with the free Azure account which includes Azure Functions.免费的 Azure 帐户附带了许多“永远免费”的服务,其中包括 Azure Functions。

As long as you stay within the free functions limit, which is currently 1,000,000 requests per month, you wouldn't have to pay anything.只要您保持在免费功能限制范围内(目前每月 1,000,000 次请求),您就无需支付任何费用。

https://azure.microsoft.com/en-us/free/free-account-faq/ https://azure.microsoft.com/en-us/free/free-account-faq/

As I known, there is not any feature about job like WebJobs for Azure WebApp or Jobs for Azure Databricks in Microsoft Azure Notebooks.据我所知,Microsoft Azure Notebooks 中没有任何关于工作的功能,例如Azure WebApp 的 WebJobsAzure Databricks 的工作 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.所以我尝试在 Azure Notebooks 的 Ubuntu 上通过crontab触发一个 Python 脚本,但失败了,因为默认的cron服务没有启动,而且 Azure 没有提供使用sudo启动cron服务的nbuser密码。

However, I also tried to write a Python script hello.py as below.但是,我也尝试编写一个 Python 脚本hello.py如下。

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.然后我在Azure Notebooks的Terminal中运行,如下图,然后关闭终端页面,运行!tail -f ~/hello.log ,好像没有被终端页面关闭事件终止。

在此处输入图片说明

在此处输入图片说明

You can try to this way.你可以试试这个方法。 If it's not what you want, I think it's impossible on Azure Notebooks.如果这不是您想要的,我认为在 Azure Notebooks 上是不可能的。

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

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