From a910b852e3d5240d517ace1ed4e12515e6c19030 Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 2 Dec 2024 21:05:11 +0800 Subject: [PATCH] tiny enhance --- examples/_thread/timer1.py | 1 + port/linux/package/pikascript/timer.py | 6 ++++-- port/linux/test/python/_thread/timer1.py | 1 + src/PikaVersion.h | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/_thread/timer1.py b/examples/_thread/timer1.py index 96a1dc3c4..0a6af2066 100644 --- a/examples/_thread/timer1.py +++ b/examples/_thread/timer1.py @@ -20,3 +20,4 @@ while len(tim.tasks) > 0: time.sleep(1) tim.stop() +time.sleep(1) diff --git a/port/linux/package/pikascript/timer.py b/port/linux/package/pikascript/timer.py index 28dda3dd1..71d2ac924 100644 --- a/port/linux/package/pikascript/timer.py +++ b/port/linux/package/pikascript/timer.py @@ -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): diff --git a/port/linux/test/python/_thread/timer1.py b/port/linux/test/python/_thread/timer1.py index 96a1dc3c4..0a6af2066 100644 --- a/port/linux/test/python/_thread/timer1.py +++ b/port/linux/test/python/_thread/timer1.py @@ -20,3 +20,4 @@ while len(tim.tasks) > 0: time.sleep(1) tim.stop() +time.sleep(1) diff --git a/src/PikaVersion.h b/src/PikaVersion.h index 82f770b96..af7b110de 100644 --- a/src/PikaVersion.h +++ b/src/PikaVersion.h @@ -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"