完成后的python线程清理

时间:2015-12-03 19:52:16

标签: python multithreading

我正在使用这种模式进行一次性的线程化任务。换句话说,他们去做有限的工作,并在他们完成时从run()函数流出。

除了在工作完成后销毁我对这个对象的引用之外,我是否还需要进行其他任何清理工作?比如打电话给join()

import threading
import Queue
import time

class MyThread(threading.Thread):                                           
    def __init__(self, shared_queue):    
        super(MyThread, self).__init__()
        if isinstance(shared_queue, Queue.Queue):
            self.shared_queue = shared_queue
        else:
            raise ValueError('shared_queue invalid type.')                                                                      
        self.start()                                                           

    def run(self):                                                             
        self.shared_queue.put('hello world')
        time.sleep(4)                                                

0 个答案:

没有答案
相关问题