简体   繁体   中英

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

I am trying to build a chat app with 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. The main thread should be looping + idling, and when the main thread sees that variable contains an exception, reraise the exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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