Creates a task on the thread's asyncio loop *without* waiting for it to finish. This is intended to be called from the parent thread as a set-and-forget. the scheduled coroutine is put on the thread's queue and is consumed by one of the thread workers.
(self, coro: Coroutine)
| 251 | self.loop.stop() |
| 252 | |
| 253 | def create_task(self, coro: Coroutine): |
| 254 | """Creates a task on the thread's asyncio loop *without* waiting for it |
| 255 | to finish. This is intended to be called from the parent thread as a |
| 256 | set-and-forget. |
| 257 | |
| 258 | the scheduled coroutine is put on the thread's queue and is |
| 259 | consumed by one of the thread workers. |
| 260 | """ |
| 261 | |
| 262 | async def _schedule_task(): |
| 263 | """Since the queue is infinite, queue.put() will not block.""" |
| 264 | await self._queue.put(coro) |
| 265 | |
| 266 | # the asyncio loop might not be running yet (if the thread was |
| 267 | # not yet started), therefore we do not block on the result. |
| 268 | return asyncio.run_coroutine_threadsafe(_schedule_task(), loop=self.loop) |
| 269 | |
| 270 | def run_coro(self, coro: Coroutine): |
| 271 | """Can be called from the main thread, but will run the coroutine on |
no outgoing calls