Skip to content

Commit

Permalink
add hku_to_async utils method
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Apr 24, 2024
1 parent 3ec9a92 commit 90cc0d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions hikyuu/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'hku_check_throw',
'hku_check_ignore',
'hku_catch',
'hku_to_async',
'hku_trace',
'hku_debug',
'hku_info',
Expand Down
9 changes: 9 additions & 0 deletions hikyuu/util/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import traceback
import functools
import asyncio
from .mylog import hku_logger


Expand Down Expand Up @@ -142,3 +143,11 @@ def wrappedFunc(*args, **kargs):
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

0 comments on commit 90cc0d9

Please sign in to comment.