python - 在 Azure Devops 发布管道中启动 Python 看门狗
问题描述
我有一种情况,我想在 Azure 发布阶段连续启动两个 Python 看门狗,然后继续执行以下任务。
据我了解,subprocess.Popen
如果您想创建像这样的“触发并忘记”行为,subprocess.Popen(["python", "mywatchdog1.py"])
那么这是一条路从 Azure Devops 中的任务(尝试使用“Powershell”和“运行 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"])
那么,subprocess.Popen
无论您是在本地运行还是在 Azure Windows 2016 代理上运行,我如何使行为方式相同?任何帮助将不胜感激。
/尼克拉斯
解决方案
那么,无论您是在本地运行还是在 Azure Windows 2016 代理上运行,如何使 subprocess.Popen 的行为方式相同?
抱歉,恐怕目前不支持这种情况。Azure Devops 管道会一一执行任务,在完成所有要在其中完成的工作之前,它不会完成当前任务。
这就是为什么它挂在你的Powershell
或Run a Python Script
任务中的原因,因为watchdog
它总是在听输入。您可以参考此文档了解更多详细信息。如果任务中有类似的东西watchdog
保持监视文件资源管理器的变化,那么根据设计,任务将无法完成。
希望我的回答能解决你的疑惑:)
推荐阅读
- c++ - 未找到体系结构 x86_64 链接器问题的符号
- html - 伪元素对齐问题
- django - AttributeError - 'DeferredAttribute' 对象没有属性 'all'
- python - UNICODE 规范化的韩文在 Tkinter 上没有正确显示
- scala - Map.keys 和 Map.values 是否以相同的顺序给出并行的元素序列?
- python - 根据索引的 1D 张量从 3D 张量中选择列(Tensorflow)
- excel - 在 VBA Excel 的 ListBox 中搜索 2 个条件
- react-native - React Native Navigation with Redux,如何使用?
- selenium - 使用 selenium chrome 驱动程序在 chrome 信息栏上显示自定义消息
- java - 以编程方式在表内创建的 JSF commandLink 不起作用