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

Method register_thread

pywebio/session/threadbased.py:292–301  ·  view source on GitHub ↗

将线程注册到当前会话,以便在线程内调用 pywebio 交互函数。 会话会一直保持直到所有通过 `register_thread` 注册的线程以及当前会话的主任务线程退出 :param threading.Thread thread: 线程对象

(self, t: threading.Thread)

Source from the content-addressed store, hash-verified

290 return callback_id
291
292 def register_thread(self, t: threading.Thread):
293 """将线程注册到当前会话,以便在线程内调用 pywebio 交互函数。
294 会话会一直保持直到所有通过 `register_thread` 注册的线程以及当前会话的主任务线程退出
295
296 :param threading.Thread thread: 线程对象
297 """
298 self.threads.append(t) # 保存 registered thread,用于主任务线程退出后等待注册线程结束
299 self.thread2session[id(t)] = self # 用于在线程内获取会话
300 event_mq = queue.Queue(maxsize=self.event_mq_maxsize) # 线程内的用户事件队列
301 self.task_mqs[self._get_task_id(t)] = event_mq
302
303 def need_keep_alive(self) -> bool:
304 # if callback thread is activated, then the session need to keep alive

Callers 4

_start_main_taskMethod · 0.95
register_threadFunction · 0.80
get_current_task_idMethod · 0.80

Calls 3

_get_task_idMethod · 0.95
idFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected