【发布时间】:2020-10-03 16:57:22
【问题描述】:
我正在编写一个带有服务器和客户端的应用程序,我想在关闭 tkinter UI 时停止服务器,但是 while 循环等待 server.accept() 并且永远不会终止,即使使用 sys.exit,顺便说一句,它正在运行线程。我在 gui close 上运行一个函数,但它不想终止。
示例如下:
while waiting_for_connection: # This is in a threaded function
conn, addr = server.accept() # It's stuck on this line while waiting for connection
thread = threading.Thread(target=handle_client, args=(conn, addr)) # Here it connects, but it doesn't reach the end of a loop if no one connects
thread.start()
有什么解决办法吗?
任何帮助将不胜感激!
【问题讨论】:
-
请提供预期的MRE。
-
@Prune 我编辑了我的帖子,看看!
-
是的。现在,也许客户端-服务器专家可以提供帮助。
-
创建话题的时候设置
daemon=True了吗?
标签: python multithreading tkinter while-loop