uuid.uuid1()什么时候创建fd泄漏?

时间:2016-04-13 06:12:56

标签: python multithreading uuid

known issue uuid.uuid1()函数在多线程环境下创建文件描述符泄漏。这可能导致服务器在达到最大打开文件数限制后崩溃。最近,我们的生产服务器正面临这个问题,我们必须每天重启它们。我试图通过示例代码复制此fd泄漏。但是,我无法这样做。以下是示例代码:

import threading
import uuid
import time

class uuidGenerator(threading.Thread):
    """multithreaded program for trying to replicate the fd leak problem in uuid.uuid1() under large number of threads"""

    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        self.generate_uuid();

    def generate_uuid(self):
        print uuid.uuid1()
        print "\n"
        time.sleep(1)

if __name__ == "__main__" :
    threads=[]
    try:
        for i in range(0,100000):
            thread=uuidGenerator()
            thread.start()
            threads.append(thread)
    except:
        print "Error: unable to start thread"

    print len(threads)
    for thread in threads:
        thread.join()
    while 1:
        pass

如何重现此问题,如何解决?

我的python版本是2.7.10

0 个答案:

没有答案