From 6388f44e8052b965644c0087afae29ec459531c4 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 5 Nov 2025 14:17:40 +0800 Subject: [PATCH] bugfix --- appPublic/worker.py | 25 ++++++++++++++++++++++++- setup.cfg | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/appPublic/worker.py b/appPublic/worker.py index 4c01774..ea83155 100755 --- a/appPublic/worker.py +++ b/appPublic/worker.py @@ -6,6 +6,29 @@ import concurrent from functools import wraps from functools import wraps +def schedule_once(seconds, coro, *args, **kw): + loop = asyncio.get_running_loop() + if inspect.iscoroutinefunction(coro): + print(f'{coro} is a coroutine') + x = loop.call_later(seconds, lambda: asyncio.create_task(coro(*args, **kw))) + else: + print(f'{coro} is a normal function') + x = loop.call_later(seconds, coro, *args, **kw) + return x + +def schedule_interval(seconds, coro, *args, **kw): + loop = asyncio.get_running_loop() + """在 asyncio 中实现 call_interval""" + def wrapper(): + if inspect.iscoroutinefunction(coro): + loop.create_task(coro(*args, **kw)) + else: + coro(*args, **kw) + return loop.call_later(seconds, wrapper) + + handle = loop.call_later(seconds, wrapper) + return handle + def get_event_loop(): try: return asyncio.get_runnung_loop() @@ -78,6 +101,6 @@ if __name__ == '__main__': await asyncio.wait(g) print('aaaaaaaaaaaaaaaaaaa') - loop = asyncio.get_event_loop() + loop = get_event_loop() loop.run_until_complete(run()) diff --git a/setup.cfg b/setup.cfg index 70700f1..8207a59 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name=appPublic -version = 5.2.11 +version = 5.3.0 description = A set of base public functions or class author = "yu moqing" author_email = "yumoqing@gmail.com"