将线程注册到当前会话,以便在线程内调用 pywebio 交互函数。 会话会一直保持直到所有通过 `register_thread` 注册的线程以及当前会话的主任务线程退出 :param threading.Thread thread: 线程对象
(self, t: threading.Thread)
| 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 |
no test coverage detected