初学python的多线程,在尝试使用单例,请问为什么会出现下面的情况?
import threading
class Index:
_lock = threading.Lock
_index = None
@staticmethod
def index():
if Index._index is None:
with Index._lock:
if Index._index is None:
Index._index = dict()
return Index._index
if __name__ == '__main__':
l = [threading.Thread(target=Index.index()) for i in range(15)]
for thread in l:
thread.start()