简体   繁体   English

Python - 尝试查找当前是否正在运行 sikuli 脚本

[英]Python - Trying to find if a sikuli script is running at the moment

So I have a sikuli script running which monitors and executes a said action every 10 minutes continuously.因此,我运行了一个 sikuli 脚本,该脚本每 10 分钟连续监视并执行一次所述动作。 However for various reasons sometimes the run is interrupted and there is no way to alert if the script stops running.然而,由于各种原因,有时运行会中断,如果脚本停止运行,则无法发出警报。

So I tried running a python script, which would monitor the window of the sikuli IDE.所以我尝试运行 python 脚本,该脚本将监控 sikuli IDE 的 window。 When the script runs, the window is no longer visible.当脚本运行时,window 不再可见。 So if the window is visible again the python script would run a batch file which would trigger the alert required.因此,如果 window 再次可见,则 python 脚本将运行一个批处理文件,该文件将触发所需的警报。 The following is the script which I made from seeing other examples here in this site:以下是我通过在此站点中查看其他示例而制作的脚本:

WindowName = "SikulixIDE 1.1.3 - C:\\Users\\TestUser\\Downloads\\testing2.sikuli"

while True:
    try:
        if win32ui.FindWindow(None, WindowName):
            subprocess.call([r'C:\Users\TestUser\Documents\notification.bat'])
            break
    except win32ui.error:
        #print("its not running!")
        continue

The problem I am running into with the above code is, even when the sikuli script is running and the IDE window (one with the WindowName) is not actually visible to me, it still finds it and goes into the if block.我在上面的代码中遇到的问题是,即使 sikuli 脚本正在运行并且 IDE window(一个带有 WindowName 的)对我来说实际上是不可见的,它仍然会找到它并进入 if 块。 I am not sure what's going wrong here, if the window is not visible in Task Manager, FindWindow shouldn't be able to find it, correct?我不确定这里出了什么问题,如果 window 在任务管理器中不可见,FindWindow 应该找不到它,对吗?

I would say you are trying to do this in very complicated way.我会说你正试图以非常复杂的方式做到这一点。

I will strongly suggest to look at '-r' option of sikuli and to write only one sikuli script that will handle exceptions by itself and will not need monitoring.我强烈建议查看 sikuli 的 '-r' 选项,并只编写一个 sikuli 脚本来自行处理异常并且不需要监控。

In this case if you really need additional monitoring for the script it will be easier since you can look for process with specific command line(instead of visible window)在这种情况下,如果您确实需要对脚本进行额外监控,这将更容易,因为您可以使用特定命令行(而不是可见窗口)查找进程

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

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