import os import time import threading import psutil import pygetwindow as gw def…
- User
import os import time import threading import psutil import pygetwindow as gw
def is_process_running(process_name): # Đảm bảo rằng các dấu nháy đều là ASCII chuẩn (’ hoặc “) không phải Unicode for process in psutil.process_iter(attrs=[‘pid’, ‘name’]): if process.info[‘name’] == process_name: return True return False
def is_process_ready(process_name): if not is_process_running(process_name): print(f"Đang chờ tiến trình {process_name} khởi chạy…”) while not is_process_running(process_name): time.sleep(1) print(f"Tiến trình {process_name} đã sẵn sàng !”) return True
def close_unique_zalo_window(): zalo_windows = gw.getWindowsWithTitle(“Zalo”) if zalo_windows: for window in zalo_windows: if window.title == “Zalo”: window.close() return True return False
def consumer(): is_process_ready(“Zalo.exe”) is_process_ready(“ZaloCall.exe”)
input(“\nNhấn ENTER để bắt đầu đếm ngược…”) countdown = 3 closed_notification_shown = False while True: if close_unique_zalo_window(): countdown = 3 if not closed_notification_shown: print(“Cửa sổ Zalo đã đóng !”) closed_notification_shown = True else: if countdown > 0: print(f"Cửa sổ tự thoát sau {countdown} giây…“) time.sleep(1) countdown -= 1 else: print(f"Đếm ngược kết thúc đến ngược thêm 5 giây nữa…”) for i in range(5, 0, -1): print(f"Thoát sau {i} giây…") time.sleep(1) print(“Thoát chương trình.”) os._exit(0)if name == “main”: consumer_thread = threading.Thread(target=consumer) consumer_thread.daemon = True consumer_thread.start()
try: while True: time.sleep(1) except KeyboardInterrupt: print(“Chương trình đã bị dừng bởi người dùng.”) os._exit(0) - Assistant