Python Library Task
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import sys
  4. sys.path.append('../..')
  5. import task
  6. import time
  7. task_num = 0
  8. def time_print(txt):
  9. sys.stdout.write(time.asctime() + ': ' + txt + '\n')
  10. def hello(rt, name):
  11. global task_num
  12. task_num += 1
  13. if task_num >= 5:
  14. rt.stop()
  15. tn = task_num
  16. time_print("(Task %d) Hello %s!" % (tn, name))
  17. time.sleep(3.8)
  18. time_print("(Task %d) Ende!" % (tn))
  19. print("task.periodic example:\n----------------------")
  20. pt = task.periodic(2, hello, "from periodic example")
  21. pt.run()
  22. try:
  23. time_print("starting...")
  24. pt.join()
  25. finally:
  26. pt.stop()