PyQt避免软件重复运行

PyQt避免软件重复运行

在Win平台下,通过应用名称获取PID,如果PID不存在,可以正常运行软件。

def get_pid(pname) -> list | None:
    result = []
    for proc in psutil.process_iter():
        if proc.name() == pname:
            result.append(proc.pid)
    return result


def check_is_have() -> bool:
    """
    检查某个软件是否可以正常运行
    True: 可以正常运行
    False: 不运行软件
    """
    pid = config.get_pid("xxx.exe")
    if pid is None or len(pid) <= 1:
        return True
    else:
        return False
posted @ 2023-06-27 14:31  CNPolaris  阅读(88)  评论(0编辑  收藏  举报