eventloop: use the default executor for run_in_thread()
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
ac55b95c1d
commit
1be639b99a
|
@ -8,7 +8,6 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
import functools
|
import functools
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Awaitable,
|
Awaitable,
|
||||||
|
@ -42,6 +41,7 @@ class EventLoop:
|
||||||
self.create_task = self.aioloop.create_task
|
self.create_task = self.aioloop.create_task
|
||||||
self.call_at = self.aioloop.call_at
|
self.call_at = self.aioloop.call_at
|
||||||
self.set_debug = self.aioloop.set_debug
|
self.set_debug = self.aioloop.set_debug
|
||||||
|
self.is_running = self.aioloop.is_running
|
||||||
|
|
||||||
def register_callback(self,
|
def register_callback(self,
|
||||||
callback: FlexCallback,
|
callback: FlexCallback,
|
||||||
|
@ -77,12 +77,11 @@ class EventLoop:
|
||||||
# was never awaited" warnings in asyncio
|
# was never awaited" warnings in asyncio
|
||||||
self.aioloop.create_task(callback())
|
self.aioloop.create_task(callback())
|
||||||
|
|
||||||
async def run_in_thread(self,
|
def run_in_thread(self,
|
||||||
callback: Callable[..., _T],
|
callback: Callable[..., _T],
|
||||||
*args
|
*args
|
||||||
) -> _T:
|
) -> Awaitable[_T]:
|
||||||
with ThreadPoolExecutor(max_workers=1) as tpe:
|
return self.aioloop.run_in_executor(None, callback, *args)
|
||||||
return await self.aioloop.run_in_executor(tpe, callback, *args)
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.aioloop.run_forever()
|
self.aioloop.run_forever()
|
||||||
|
|
Loading…
Reference in New Issue