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.

tqueue.py 650B

1234567891011121314151617181920212223242526272829303132
  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.queue example:\n----------------------")
  20. q = task.queue()
  21. q.enqueue(5, hello, "from queue example (5)")
  22. q.enqueue(6, hello, "from queue example (6)")
  23. q.enqueue(4, hello, "from queue example (4)")
  24. q.run()