Answer the question
In order to leave comments, you need to log in
Multiprocessing why executes the main code?
print("начало")
def aa():
time.sleep(1)
print("Конец кода")
if __name__ == '__main__':
p = Process(target=aa)
p2 = Process(target=aa)
p3 = Process(target=aa)
p.start()
p2.start()
p3.start()
начало
начало
начало
начало
Конец кода
Конец кода
Конец кода
Answer the question
In order to leave comments, you need to log in
Because each new process is a separate Python interpreter that re-imports the script, and when importing, all top-level instructions are executed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question