Skip to content

Commit 56e0a10

Browse files
committed
set default eventloop period to 10ms
1 parent d249c0c commit 56e0a10

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

examples/eventloop/once2.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import eventloop
2+
from PikaStdLib import MemChecker
3+
import time
4+
5+
eventloop._is_debug = True
6+
expect_finished = 10
7+
finished = 0
8+
9+
def test_func(arg1, arg2):
10+
global finished
11+
finished += 1
12+
print("finished:", finished)
13+
print("Running test function with arguments:", arg1, arg2)
14+
MemChecker().now()
15+
16+
17+
MemChecker().now()
18+
for i in range(expect_finished):
19+
eventloop.start_new_task_once(
20+
test_func, ("Hello", " World"), delay_ms=100)
21+
MemChecker().now()
22+
23+
while finished < expect_finished:
24+
time.sleep(0.1)
25+
eventloop.stop()

package/eventloop/eventloop.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(self, func, callback, args, period_ms, delay_ms):
2323
:param args: arguments of func
2424
:param period_ms: period of periodic task
2525
"""
26+
if period_ms != None:
27+
self._is_periodic = True
28+
2629
self._func = func
2730
self._callback = callback
2831
self._args = args
@@ -33,8 +36,12 @@ def __init__(self, func, callback, args, period_ms, delay_ms):
3336
period_ms = 0
3437
self._last_call_time = time.tick_ms() - period_ms + delay_ms
3538
_debug('last_call_time for delay:', self._last_call_time)
36-
if period_ms != None:
37-
self._is_periodic = True
39+
_debug('func:', self._func)
40+
_debug('callback:', self._callback)
41+
_debug('args:', self._args)
42+
_debug('period_ms:', self._period_ms)
43+
_debug('delay_ms:', self._delay_ms)
44+
_debug('is_periodic:', self._is_periodic)
3845

3946

4047
class EventLoop:
@@ -48,7 +55,7 @@ class EventLoop:
4855
_started = False
4956
_uuid = 0
5057

51-
def __init__(self, period_ms=100, thread_stack=0):
58+
def __init__(self, period_ms=10, thread_stack=0):
5259
"""
5360
:param period_ms: period of loop
5461
:param thread_stack: stack size of thread
@@ -60,12 +67,7 @@ def _add_task(self, task_name, func, callback, args, period_ms, delay_ms):
6067
if task_name == None:
6168
self._uuid += 1
6269
task_name = str(self._uuid)
63-
_debug('add_task', task_name)
64-
_debug('func', func)
65-
_debug('callback', callback)
66-
_debug('args', args)
67-
_debug('period_ms', period_ms)
68-
_debug('delay_ms', delay_ms)
70+
_debug('create task:', task_name)
6971
new_task = EventTask(func, callback, args, period_ms, delay_ms)
7072
self._tasks[task_name] = new_task
7173

port/linux/package/pikascript/eventloop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class EventLoop:
5555
_started = False
5656
_uuid = 0
5757

58-
def __init__(self, period_ms=100, thread_stack=0):
58+
def __init__(self, period_ms=10, thread_stack=0):
5959
"""
6060
:param period_ms: period of loop
6161
:param thread_stack: stack size of thread

0 commit comments

Comments
 (0)