There is a known issue that uuid.uuid1() function creates a file descriptor leak under multi threaded environments. This can cause servers to crash after reaching the limit of max number of open files. Recently, our production servers are facing this issue and we have to restart them everyday. I am trying to replicate this fd leak through a sample code. However, I am unable to do so. Here is the sample code:
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
How can I reproduce this issue, and how can I fix it?
My python version is 2.7.10