Blue Hawk
Blue Hawk

Reputation: 3

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.

Upvotes: 0

Views: 1271

Answers (1)

pepoluan
pepoluan

Reputation: 6780

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.

Upvotes: 1

Related Questions