test1.py 664 B

1234567891011121314151617181920212223242526272829303132
  1. import time
  2. from eventloop import EventLoop
  3. finished = False
  4. eventloop.set_debug(True)
  5. def test_func(arg1, arg2):
  6. print("Running test function with arguments:", arg1, arg2)
  7. return arg1 + arg2
  8. def test_callback(res):
  9. global finished
  10. print("Running test callback function", res)
  11. assert res == "Hello World"
  12. finished = True
  13. # Test case 1: Add and run a one-time task
  14. event_loop = EventLoop(period_ms=100)
  15. event_loop.start_new_task_once(
  16. test_func, ("Hello", " World"), callback=test_callback)
  17. event_loop.start()
  18. # Sleep for enough time to allow the one-time task to run
  19. while not finished:
  20. time.sleep(0.1)
  21. event_loop.stop()