How to exit command prompt console after sending disconnect command from tkinter?

I’m trying to create tkinter app with commands to control automated script replay on chrome.

Usecase:

  1. .bat launches autoamted replay where I get sessionid and pass it to debugger
  2. connect_debugger_async connects to the current chrome session based on sessionid and I see ‘debugger attached’ message in cmd prompt console.
  3. Similarly when I invoke pause_debugger action from python, I see command reaching command prompt and pause action does happen on debugger where script execution is paused.
  4. But, when disconnect_debugger is invoked, I see command reaching command prompt but it is not complete.

Expected: On disconnect_debugger, I expect cursor should exit from command prompt and point to current working directory

Example: C:/Temp

Actual: On disconnect_debugger, cursor is not exiting from command prompt and exits only when i close the tkinter app.

Below is my code snippet:

import subprocess
import asyncio
import websockets
import json
import tkinter as tk
from tkinter import messagebox

class DebuggerControlApp(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("Debugger Control")
        self.geometry("300x200")
    self.launch_button = tk.Button(self, text="Launch Browser", command=self.launch_browser)
    self.launch_button.pack(pady=10)

    self.connect_button = tk.Button(self, text="Connect Debugger", command=self.connect_debugger)
    self.connect_button.pack(pady=10)

    self.pause_button = tk.Button(self, text="Pause Debugger", command=self.pause_debugger)
    self.pause_button.pack(pady=10)

    self.disconnect_button = tk.Button(self, text="Disconnect Debugger", command=self.disconnect_debugger)
    self.disconnect_button.pack(pady=10)

def launch_browser(self):
    subprocess.Popen(["launch_browser.bat"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    messagebox.showinfo("Info", "Browser Launched")

async def send_debugger_command(self, command):
    async with websockets.connect('ws://localhost:9222/<session_id>') as websocket:
        await websocket.send(json.dumps(command))
        response = await websocket.recv()
        return json.loads(response)

async def connect_debugger_async(self):
    command = {
        "id": 1,
        "method": "Debugger.enable"
    }
    response = await self.send_debugger_command(command)
    messagebox.showinfo("Info", f"Connected to debugger: {response}")

def connect_debugger(self):
    asyncio.run(self.connect_debugger_async())

async def pause_debugger_async(self):
    command = {
        "id": 2,
        "method": "Debugger.pause"
    }
    response = await self.send_debugger_command(command)
    messagebox.showinfo("Info", f"Debugger paused: {response}")

def pause_debugger(self):
    asyncio.run(self.pause_debugger_async())

async def disconnect_debugger_async(self):
    command = {
        "id": 3,
        "method": "Debugger.disable"
    }
    response = await self.send_debugger_command(command)
    messagebox.showinfo("Info", f"Disconnected from debugger: {response}")

def disconnect_debugger(self):
    asyncio.run(self.disconnect_debugger_async())

if __name__ == "__main__":
    app = DebuggerControlApp()
    app.mainloop()

Note: If I open subprocess in a new console then communicating between two command prompts was not possible, i.e., cmd prompt which launched py and cmd prompt which launched script execution, how to attach and control actions happening on second cmd?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật