#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys sys.path.append('../..') import task import time task_num = 0 def time_print(txt): sys.stdout.write(time.asctime() + ': ' + txt + '\n') def hello(rt, name): global task_num task_num += 1 if task_num >= 5: rt.stop() tn = task_num time_print("(Task %d) Hello %s!" % (tn, name)) time.sleep(3.8) time_print("(Task %d) Ende!" % (tn)) print("task.threaded_queue example:\n-------------------------------") tq = task.threaded_queue() tq.enqueue(5, hello, "from queue example (5)") tq.enqueue(6, hello, "from queue example (6)") tq.enqueue(4, hello, "from queue example (4)") tq.run() try: time_print("starting...") tq.join() finally: tq.stop()