简体   繁体   English

Python 线程 - 获取不说明发生了什么的回溯

[英]Python threading— Getting a traceback that does not tell what has happened

I am trying to build a chat app with python sockets.我正在尝试使用 python sockets 构建一个聊天应用程序。 I want that my program always recieives message therefore, I used threading but I am getting a traceback that does not tell what has happened.我希望我的程序总是收到消息,因此我使用了线程,但我得到了一个不告诉发生了什么的回溯。 Simply,简单地,

PS C:\Users\rauna> python "c:/Users/rauna/Documents/New folder/meg.py"
S or Cc
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 954, in _bootstrap_inner

on client side and在客户端和

C:\Users\rauna\Documents\New folder>C:/Users/rauna/AppData/Local/Microsoft/WindowsApps/python.exe "c:/Users/rauna/Documents/New folder/meg.py"    
S or Cs
Connection from: ('192.168.43.114', 50802)
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 954, in _bootstrap_inner

on server side.在服务器端。 Here , is the complete code. 这里,是完整的代码。

You need to capture the exception within the thread itself, and "transfer" the exception to the main thread.您需要在线程本身内捕获异常,并将异常“转移”到主线程。

Wrap your thread code in try...except , grab the exception, and stuff it inside a variable that the main thread can see.将您的线程代码包装在try...except中,获取异常,并将其填充到主线程可以看到的变量中。 The main thread should be looping + idling, and when the main thread sees that variable contains an exception, reraise the exception.主线程应该是looping + idling,当主线程看到该变量包含异常时,重新引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM