'python 3.10 "os.system" command kills tkinter GUI

While I figured this out by myself, I am stuck with another problem.

As soon as os.system("taskkill /PID " + p.decode('UTF-8')[-8:].lstrip()) gets executed, the tkinter GUI gets shutdown. The actual issue might be called earlier during creation of a subprocess.

def reconn():
    global connected
    global s
    p = subprocess.Popen("netstat -a -n -o |find \"" + HOST + ":" + str(PORT) + "\"", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
    os.system("taskkill /PID " + p.decode('UTF-8')[-8:].lstrip())
    showGUI()
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    connected = False

the showGUI() function simply reopens the GUI, which wouldn't be necessary if it won't close in the first place.

Check out the link for the full code.



Sources

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

Source: Stack Overflow

Solution Source