Pregunta

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)

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top