Skip to content

Commit 2ec4125

Browse files
committed
fix: uncaught SessionClosedException in callback of thread-based session
1 parent 8b198e4 commit 2ec4125

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pywebio/session/threadbased.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def main_task(target):
111111
thread.start()
112112

113113
def send_task_command(self, command):
114-
"""向会话发送来自协程内的消息
114+
"""向会话发送来自pywebio应用的消息
115115
116116
:param dict command: 消息
117117
"""
@@ -252,10 +252,12 @@ def _dispatch_callback_event(self):
252252
def run(callback):
253253
try:
254254
callback(event['data'])
255-
except Exception:
255+
except Exception as e:
256256
# 子类可能会重写 get_current_session ,所以不要用 ThreadBasedSession.get_current_session 来调用
257-
self.get_current_session().on_task_exception()
258-
# todo: clean up from `register_thread()`
257+
if not isinstance(e, SessionException):
258+
self.on_task_exception()
259+
260+
# todo: good to have -> clean up from `register_thread()`
259261

260262
if mutex:
261263
run(callback)

0 commit comments

Comments
 (0)