【问题标题】:Launching a Python watchdog in an Azure Devops Release pipeline在 Azure Devops 发布管道中启动 Python 看门狗
【发布时间】:2020-02-14 10:40:33
【问题描述】:

我有一种情况,我想在 Azure 发布阶段连续启动两个 Python 看门狗,然后继续执行以下任务。

据我了解,subprocess.Popen 是您想要创建这样的“即开即忘”行为的最佳选择 当我在 Azure 之外运行 subprocess.Popen(["python", "mywatchdog1.py"]) 之类的东西时,它的行为符合我的预期,它“触发并忘记”,但是当从任务运行相同的调用时(尝试使用“Powershell”和“Run在 Azure Devops 中使用 Python 脚本”),任务停止并等待看门狗进程完成。

这是一个例子:

# mywatchdog1.py

import time
import os
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler

class MyWatchdogEventHandler(LoggingEventHandler):

    def dispatch(self, event):
        print(f"A new dog was created")


if __name__ == "__main__":
    dog_file_path = "c:\\dogs"
    event_handler = MyWatchdogEventHandler()
    observer = Observer()
    observer.schedule(event_handler, dog_file_path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

这就是我尝试使用以下方式启动的内容:

import subprocess as sp

if __name__ == "__main__":
    sp.Popen(["python", "C:\\scripts\\mywatchdog01.py"])

那么,无论您在本地运行还是在 Azure Windows 2016 代理上运行,我如何使 subprocess.Popen 的行为方式相同?任何帮助将不胜感激。

/尼克拉斯

【问题讨论】:

    标签: python python-3.x azure-devops subprocess python-watchdog


    【解决方案1】:

    那么,我如何让 subprocess.Popen 行为相同,无论是否 您在本地运行还是在 Azure Windows 2016 代理上运行?

    抱歉,恐怕目前不支持这种情况。 Azure Devops 管道会一一执行任务,它不会完成当前任务,直到它完成所有要在其中完成的工作。

    这就是为什么它挂在你的PowershellRun a Python Script 任务中的原因是watchdog 总是在监听输入。您可以参考this document了解更多详情。如果任务中存在watchdog 之类的内容,则根据设计,任务将无法完成,从而持续监视文件资源管理器的更改。

    希望我的回答有助于解决你的困惑:)

    【讨论】:

      猜你喜欢
      • 2019-03-07
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 2019-02-18
      • 2019-04-29
      • 2022-12-05
      • 1970-01-01
      相关资源
      最近更新 更多