Python Library Task
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

threaded_queue.py 754B

12345678910111213141516171819202122232425262728293031323334353637
  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.threaded_queue example:\n-------------------------------")
  20. tq = task.threaded_queue()
  21. tq.enqueue(5, hello, "from queue example (5)")
  22. tq.enqueue(6, hello, "from queue example (6)")
  23. tq.enqueue(4, hello, "from queue example (4)")
  24. tq.run()
  25. try:
  26. time_print("starting...")
  27. tq.join()
  28. finally:
  29. tq.stop()