I tried to create a new object in a process when using multiprocessing module. However, something confuses me.
When I use multiprocessing module, the id of the new object is the same
for i in range(4):
p = multiprocessing.Process(target=worker)
p.start()
def worker():
# stanford named entity tagger
st = StanfordNERTagger(model_path,stanford_ner_path)
print id(st) # all the processes print the same id
But when I use threading, they are different:
for i in range(4):
p = threading.Thread(target=worker)
p.start()
def worker():
# stanford named entity tagger
st = StanfordNERTagger(model_path,stanford_ner_path)
print id(st) # threads print differnt ids
I am wondering why they are different.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…