异步运行协程对象。可以在协程内调用 PyWebIO 交互函数 :param coro_obj: 协程对象 :return: An instance of `TaskHandler` is returned, which can be used later to close the task.
(self, coro_obj)
| 221 | return callback_task.coro_id |
| 222 | |
| 223 | def run_async(self, coro_obj): |
| 224 | """异步运行协程对象。可以在协程内调用 PyWebIO 交互函数 |
| 225 | |
| 226 | :param coro_obj: 协程对象 |
| 227 | :return: An instance of `TaskHandler` is returned, which can be used later to close the task. |
| 228 | """ |
| 229 | assert asyncio.iscoroutine(coro_obj), '`run_async()` only accept coroutine object' |
| 230 | |
| 231 | self._alive_coro_cnt += 1 |
| 232 | |
| 233 | task = Task(coro_obj, session=self, on_coro_stop=self._on_task_finish) |
| 234 | self.coros[task.coro_id] = task |
| 235 | asyncio.get_event_loop().call_soon_threadsafe(task.step) |
| 236 | return task.task_handle() |
| 237 | |
| 238 | async def run_asyncio_coroutine(self, coro_obj): |
| 239 | """若会话线程和运行事件的线程不是同一个线程,需要用 asyncio_coroutine 来运行asyncio中的协程""" |
no test coverage detected