Skip to content

Commit e8ae3b2

Browse files
committed
fix #243: thread keep alive after session closed
1 parent 4fd622b commit e8ae3b2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pywebio/io_ctrl.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def __init__(self, spec, on_embed=None):
7979
self.custom_enter = None
8080
self.custom_exit = None
8181

82+
# Try to make sure current session exist.
83+
# If we leave the session interaction in `Output.__del__`,
84+
# the Exception raised from there will be ignored by python interpreter,
85+
# thus we can't end some session in some cases.
86+
# See also: https://github.com/pywebio/PyWebIO/issues/243
87+
get_current_session()
88+
8289
def enable_context_manager(self, container_selector=None, container_dom_id=None, custom_enter=None,
8390
custom_exit=None):
8491
self.enabled_context_manager = True
@@ -157,7 +164,11 @@ def onclick(self, callback):
157164
def __del__(self):
158165
"""返回值没有被变量接收时的操作:直接输出消息"""
159166
if not self.processed:
160-
self.send()
167+
# avoid `Exception ignored in xxx` error log
168+
try:
169+
self.send()
170+
except Exception:
171+
pass
161172

162173

163174
class OutputList(UserList):

0 commit comments

Comments
 (0)