문제

I have the following while loop in my Python script

while 1:   
    functionToGetXandY
    if x == z:
        os.system("google-chrome --start-maximized " + x)
        currentLink = latestLink

    if y == z:
         subprocess.call([vlc_path, "--fullscreen", z])

    time.sleep(1)

Whenever Chrome or VLC is started through the script the loop seems to stop - or sometimes wait until the opened window is closed. What am I missing?

Note: The infinite loop is on purpose - the script continuously checks an XML file to execute a command (that part works)

도움이 되었습니까?

해결책

Both subprocess.call and os.system are blocking calls. This means that when you call either of them, your script pauses until the program you called exits.

If you want your Python script to continue executing immediately, you may want to look into subprocess.Popen which is non-blocking and takes pretty much the same arguments subprocess.call takes

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top