I’m pretty new to python (using 3.12) programming, here I’m closing a server which is running on port 8080.
cmd_find_pid = f'netstat -aon | findstr :8080 | findstr LISTENING'
pid = subprocess.check_output(cmd_find_pid, shell=True, text=True, stderr=subprocess.STDOUT)
# Extract PID
pid = pid.strip().split()[-1]
cmd_kill = f'taskkill /F /PID {pid}'
subprocess.Popen(cmd_kill, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
I’m able to get the Pid and close the port using the above statement but the problem here is the main thread execution is getting blocked after running subporcess.Popen