test3.py 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import time
  2. import eventloop
  3. run_time = 0
  4. eventloop.set_debug(True)
  5. def test_func(arg1, arg2):
  6. global run_time
  7. run_time += 1
  8. print("Running test function with arguments:", arg1, arg2)
  9. return arg1 + arg2
  10. def test_func2():
  11. print("test function 2")
  12. def test_func3(arg):
  13. print("test function 3 with argument:", arg)
  14. def test_callback(res):
  15. print("Running test callback function", res)
  16. assert res == "Hello World"
  17. eventloop.start_new_task(test_func, ("Hello", " World"))
  18. eventloop.start_new_task_periodic(
  19. test_func2, (),
  20. period_ms=200
  21. )
  22. eventloop.start_new_task_once(test_func3, ("Hello"))
  23. # Sleep for enough time to allow the periodic task to run multiple times
  24. while run_time < 3:
  25. time.sleep(0.1)
  26. # Test case 3: Test removing a task
  27. eventloop.start_new_task_periodic(
  28. test_func, ("Hello", " World"), callback=test_callback, task_name="test_task_remove")
  29. eventloop.remove_task("test_task_remove")