@@ -0,0 +1,1259 @@
+import Queue%0Aimport threading%0A%0Aclass JobManager (threading.Thread):%0A    def __init__(self, threadID):%0A        threading.Thread.__init__(self)%0A        self.threadID = threadID%0A    def run(self):%0A        while True:%0A            # Monitor lock and check%0A            condition.acquire()%0A            if main_queue.empty():%0A                condition.wait()%0A            %0A            # Launch the task%0A            task,inputdata = main_queue.get()%0A            print task%0A            %0A            # Monitor notify%0A            condition.notify()%0A            condition.release()%0A%0Adef addJob(task, inputdata):%0A    # Monitor lock%0A    condition.acquire()%0A    %0A    # Put task in the job queue%0A    main_queue.put((task,inputdata))%0A    addJob.cur_id  += 1%0A    jobId = 'job' + %60addJob.cur_id%60%0A    main_dict%5BjobId%5D = None%0A    %0A    # Monitor notify%0A    condition.notify()%0A    condition.release()%0A    %0A    # Returns the jobId%0A    return jobId%0A%0Adef isDone(jobId):%0A    return main_dict%5BjobId%5D != None%0A%0Adef getResult(jobId):%0A    return main_dict%5BjobId%5D%0A%0A# Initialization%0AaddJob.cur_id = 0 # static variable%0Acondition = threading.Condition()%0Amain_queue = Queue.Queue()%0Amain_dict = %7B%7D%0A%0A# Launch the main thread%0Amain_thread = JobManager(1)%0Amain_thread.daemon = True%0Amain_thread.start()%0A

job manager