mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
fix event once err when delay_ms is set
This commit is contained in:
parent
b0989728be
commit
451c51735a
@ -23,6 +23,9 @@ class EventTask:
|
||||
:param args: arguments of func
|
||||
:param period_ms: period of periodic task
|
||||
"""
|
||||
if period_ms != None:
|
||||
self._is_periodic = True
|
||||
|
||||
self._func = func
|
||||
self._callback = callback
|
||||
self._args = args
|
||||
@ -33,8 +36,12 @@ class EventTask:
|
||||
period_ms = 0
|
||||
self._last_call_time = time.tick_ms() - period_ms + delay_ms
|
||||
_debug('last_call_time for delay:', self._last_call_time)
|
||||
if period_ms != None:
|
||||
self._is_periodic = True
|
||||
_debug('func:', self._func)
|
||||
_debug('callback:', self._callback)
|
||||
_debug('args:', self._args)
|
||||
_debug('period_ms:', self._period_ms)
|
||||
_debug('delay_ms:', self._delay_ms)
|
||||
_debug('is_periodic:', self._is_periodic)
|
||||
|
||||
|
||||
class EventLoop:
|
||||
@ -60,12 +67,7 @@ class EventLoop:
|
||||
if task_name == None:
|
||||
self._uuid += 1
|
||||
task_name = str(self._uuid)
|
||||
_debug('add_task', task_name)
|
||||
_debug('func', func)
|
||||
_debug('callback', callback)
|
||||
_debug('args', args)
|
||||
_debug('period_ms', period_ms)
|
||||
_debug('delay_ms', delay_ms)
|
||||
_debug('create task:', task_name)
|
||||
new_task = EventTask(func, callback, args, period_ms, delay_ms)
|
||||
self._tasks[task_name] = new_task
|
||||
|
||||
|
25
test/python/eventloop/once2.py
Normal file
25
test/python/eventloop/once2.py
Normal file
@ -0,0 +1,25 @@
|
||||
import eventloop
|
||||
from PikaStdLib import MemChecker
|
||||
import time
|
||||
|
||||
eventloop._is_debug = True
|
||||
expect_finished = 10
|
||||
finished = 0
|
||||
|
||||
def test_func(arg1, arg2):
|
||||
global finished
|
||||
finished += 1
|
||||
print("finished:", finished)
|
||||
print("Running test function with arguments:", arg1, arg2)
|
||||
MemChecker().now()
|
||||
|
||||
|
||||
MemChecker().now()
|
||||
for i in range(expect_finished):
|
||||
eventloop.start_new_task_once(
|
||||
test_func, ("Hello", " World"), delay_ms=100)
|
||||
MemChecker().now()
|
||||
|
||||
while finished < expect_finished:
|
||||
time.sleep(0.1)
|
||||
eventloop.stop()
|
@ -40,6 +40,7 @@ TEST_RUN_SINGLE_FILE(eventloop, test2, "test/python/eventloop/test2.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, test3, "test/python/eventloop/test3.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, delay1, "test/python/eventloop/delay1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, once1, "test/python/eventloop/once1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, once2, "test/python/eventloop/once2.py")
|
||||
|
||||
#endif
|
||||
TEST_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user