I am programming a Kahoot!-like game in python with both server code and client code.
I am using tkinter and using multithreading in the program.
Unfortunately I am getting this error: "Tcl_AsyncDelete:async handler deleted by the wrong thread". The error comes after the program disconnects and the window closes.
if __name__ == "__main__":
matplotlib.use('Agg')
name = get_user_name()
topic = get_selected_category()
SERVER_IP = '127.0.0.2' # Replace with the server's IP address
SERVER_PORT = 1100 # Replace with the server's port
# Connect to the server
global client_socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((SERVER_IP, SERVER_PORT))
# Receive and print the client ID assigned by the server
client_id = client_socket.recv(1024).decode('utf-8')
print(f"Connected to the server as Client {client_id}")
receive_threadd = threading.Thread(target=client_receive)
receive_threadd.start()
receive_threadd.join()
print("the thread closed now")
At the terminal, I get:
the thread closed now
Tcl_AsyncDelete: async handler deleted by the wrong thread
Process finished with exit code -2147483645
I searched online and saw that using the commands: gc.collect()ormatplotlib.use('Agg')` might help but they did not help.
I put gc.collect() after every closing the window with root.destroy(),
and the matplotlib.use('Agg') I put first in the main function
Does anyone know another command or a method to solve this error?