test1.py 680 B

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