mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
tiny enhance
This commit is contained in:
parent
b4c2d2da03
commit
a910b852e3
@ -20,3 +20,4 @@ while len(tim.tasks) > 0:
|
||||
time.sleep(1)
|
||||
|
||||
tim.stop()
|
||||
time.sleep(1)
|
||||
|
@ -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):
|
||||
|
@ -20,3 +20,4 @@ while len(tim.tasks) > 0:
|
||||
time.sleep(1)
|
||||
|
||||
tim.stop()
|
||||
time.sleep(1)
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user