forked from pikasTech/PikaPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.py
More file actions
45 lines (29 loc) · 957 Bytes
/
test3.py
File metadata and controls
45 lines (29 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
import eventloop
run_time = 0
eventloop.set_debug(True)
def test_func(arg1, arg2):
global run_time
run_time += 1
print("Running test function with arguments:", arg1, arg2)
return arg1 + arg2
def test_func2():
print("test function 2")
def test_func3(arg):
print("test function 3 with argument:", arg)
def test_callback(res):
print("Running test callback function", res)
assert res == "Hello World"
eventloop.start_new_task(test_func, ("Hello", " World"))
eventloop.start_new_task_periodic(
test_func2, (),
period_ms=20
)
eventloop.start_new_task_once(test_func3, ("Hello"))
# Sleep for enough time to allow the periodic task to run multiple times
while run_time < 3:
time.sleep(0.1)
# Test case 3: Test removing a task
eventloop.start_new_task_periodic(
test_func, ("Hello", " World"), callback=test_callback, task_name="test_task_remove")
eventloop.remove_task("test_task_remove")