Код: Выделить всё
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)
Подробнее здесь: https://stackoverflow.com/questions/787 ... ng-blocked