簡體   English   中英

Python 線程 - 獲取不說明發生了什么的回溯

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

我正在嘗試使用 python sockets 構建一個聊天應用程序。 我希望我的程序總是收到消息,因此我使用了線程,但我得到了一個不告訴發生了什么的回溯。 簡單地,

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

在客戶端和

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

在服務器端。 這里,是完整的代碼。

您需要在線程本身內捕獲異常,並將異常“轉移”到主線程。

將您的線程代碼包裝在try...except中,獲取異常,並將其填充到主線程可以看到的變量中。 主線程應該是looping + idling,當主線程看到該變量包含異常時,重新引發異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM