'Python subprocess.run() not responding on PySimpleGUI

When I run the sample code below and click on the button, the GUI window shows not responding? Maybe because The GUI is waiting for the subprocess.run() to finish, because when I close the browser that is opened by the GUI, it is not responding anymore. How can I use the GUI when using subprocess.run()? Thanks. Here is my sample code:

import PySimpleGUI as sg
import subprocess

layout = [
     [sg.Button('Open Browser', key="ob")]
]

window = sg.Window('Metamask Accounts Opener', layout, element_justification='c', size=(400, 400))

while True:
    event, values = window.read()

    if event == sg.WIN_CLOSED or event == 'Exit':  # if user closes window or clicks cancel
        break

    if event == "ob":
        subprocess.run('"C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe" --remote-debugging-port=9222 -- "%1"')

window.close()


Solution 1:[1]

subprocess.run waits for the process to finish. You need to use Popen in order to not wait and just run in the background.

Popen(['"C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"' ,"--remote-debugging-port=9222","--","%1"])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MarkosTh09