Running python 2.7 on windows 7 (64bit).
When reading the docs for library module multiprocessing
, it states several times the importance of the __main__
module, including the conditional (especially in Windows):
if __name__ == "__main__":
# create Process() here
My understanding, is that you don't want to create Process() instances in the global namespace of the module (because when the child process imports the module, he will spawn yet another inadvertently).
I do not have to place Process managers at the very top level of my package execution hierarchy though (execution in the PARENT). As long as my Process()'s are created, managed, and terminated in a class method, or even in a function closure. Just not in the toplevel module namespace.
Am I understanding this warning/requirement correctly?
EDIT
After the first two responses, I add this quotation. This is in the introduction for Section 16.6 multiprocessing from the 2.7 docs.
Note: Functionality within this package requires that the __main__
module be importable by the children. This is covered in Programming
guidelines however it is worth pointing out here.This means that some
examples, such as the multiprocessing.Pool
examples will not work in
the interactive interpreter...
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…