eventloop: use the default executor for run_in_thread()

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-01-28 16:58:39 -05:00
parent ac55b95c1d
commit 1be639b99a
1 changed files with 6 additions and 7 deletions

View File

@ -8,7 +8,6 @@ from __future__ import annotations
import asyncio
import inspect
import functools
from concurrent.futures import ThreadPoolExecutor
from typing import (
TYPE_CHECKING,
Awaitable,
@ -42,6 +41,7 @@ class EventLoop:
self.create_task = self.aioloop.create_task
self.call_at = self.aioloop.call_at
self.set_debug = self.aioloop.set_debug
self.is_running = self.aioloop.is_running
def register_callback(self,
callback: FlexCallback,
@ -77,12 +77,11 @@ class EventLoop:
# was never awaited" warnings in asyncio
self.aioloop.create_task(callback())
async def run_in_thread(self,
callback: Callable[..., _T],
*args
) -> _T:
with ThreadPoolExecutor(max_workers=1) as tpe:
return await self.aioloop.run_in_executor(tpe, callback, *args)
def run_in_thread(self,
callback: Callable[..., _T],
*args
) -> Awaitable[_T]:
return self.aioloop.run_in_executor(None, callback, *args)
def start(self):
self.aioloop.run_forever()