Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Switch to or open a process in the background - python

Hillo When the user clicks on the program icon, there is a code that checks whether the program is running in the background or not, if the condition is met, the switch to or open this background process, or the program opens again if it was not running before (I have a problem because it opens more than once in the taskbar)

def process():
    import psutil
    PROCNAME = 'test.exe'
    for proc in psutil.process_iter():
        try:
            if proc.name().lower() == PROCNAME.lower():
                return
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    MainThred = QApplication([])
    MainGUI = MainWindow()
    MainGUI.show()
    sysExit(MainThred.exec_())
if __name__ == "__main__":
    process()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...