MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / _start_main_task

Method _start_main_task

pywebio/session/threadbased.py:81–114  ·  view source on GitHub ↗
(self, target)

Source from the content-addressed store, hash-verified

79 self._start_main_task(target)
80
81 def _start_main_task(self, target):
82
83 @wraps(target)
84 def main_task(target):
85 try:
86 target()
87 except Exception as e:
88 if not isinstance(e, SessionException):
89 self.on_task_exception()
90 finally:
91 for t in self.threads:
92 if t.is_alive() and t is not threading.current_thread():
93 t.join()
94
95 try:
96 if self.need_keep_alive():
97 from ..session import hold
98 hold()
99 else:
100 self.send_task_command(dict(command='close_session'))
101 except SessionException: # ignore SessionException error
102 pass
103 finally:
104 # we need first trigger close event and then perform close operation,
105 # because close operation will clean up all resources in this session,
106 # which may need to be accessed in close event
107 self._trigger_close_event()
108 self.close()
109
110 thread = threading.Thread(target=main_task, kwargs=dict(target=target),
111 daemon=True, name='main_task')
112 self.register_thread(thread)
113
114 thread.start()
115
116 def send_task_command(self, command):
117 """向会话发送来自pywebio应用的消息

Callers 1

__init__Method · 0.95

Calls 1

register_threadMethod · 0.95

Tested by

no test coverage detected