add hku_to_async utils method

This commit is contained in:
fasiondog 2024-04-24 20:02:32 +08:00
parent 3ec9a92386
commit 90cc0d93d7
2 changed files with 10 additions and 0 deletions

View File

@ -25,6 +25,7 @@ __all__ = [
'hku_check_throw',
'hku_check_ignore',
'hku_catch',
'hku_to_async',
'hku_trace',
'hku_debug',
'hku_info',

View File

@ -10,6 +10,7 @@
import sys
import traceback
import functools
import asyncio
from .mylog import hku_logger
@ -142,3 +143,11 @@ def hku_catch(ret=None, trace=False, callback=None, retry=1, with_msg=False, re_
return wrappedFunc
return hku_catch_wrap
def hku_to_async(func):
@functools.wraps(func)
async def async_func(*args, **kwargs):
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, func, *args, **kwargs)
return async_func