tiny enhance

This commit is contained in:
lyon 2024-12-02 21:05:11 +08:00
parent b4c2d2da03
commit a910b852e3
4 changed files with 7 additions and 3 deletions

View File

@ -20,3 +20,4 @@ while len(tim.tasks) > 0:
time.sleep(1)
tim.stop()
time.sleep(1)

View File

@ -1,6 +1,7 @@
import _thread
import time
class Timer:
def __init__(self, tick_ms=10):
self.tick_ms = tick_ms
@ -16,14 +17,15 @@ class Timer:
def run(self):
while self.is_running:
time.sleep_ms(self.tick_ms)
tick_now = time.tick_ms()
for task in self.tasks:
time_end, func, args = task
if time.tick_ms() >= time_end:
if tick_now >= time_end:
func(*args)
self.tasks.remove(task)
if self.debug:
print('tasks after run:', len(self.tasks))
time.sleep_ms(self.tick_ms)
self.stoped = True
def stop(self):

View File

@ -20,3 +20,4 @@ while len(tim.tasks) > 0:
time.sleep(1)
tim.stop()
time.sleep(1)

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 13
#define PIKA_VERSION_MICRO 4
#define PIKA_EDIT_TIME "2024/12/02 20:54:06"
#define PIKA_EDIT_TIME "2024/12/02 21:04:57"