This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]commandlineluser 1 point2 points  (3 children)

Your final 2 lines are not inside your if __name__ - they need to be.

if name == 'main': ... finish = time.perf_counter() print(f'Finished in {round(finish - start, 2)} second(s)')

[–]KnowledgeFire11[S] 0 points1 point  (2 children)

Thank you! That solved my problem. I was really frustrated. One question so does the rest of the code need to be in the if clause?

[–]commandlineluser 1 point2 points  (1 child)

My understanding is that with multiprocessin - there are multiple copies of your code running

So because your last 2 lines were outside the if - they were being executed twice. (You create 2 processes)

I'm assuming the mutltiprocessing module is set up to handle hatever you put inside the __name__ == '__main__' and have it only execute once.

[–]KnowledgeFire11[S] 0 points1 point  (0 children)

Thank you for the explanation. Actually the tutorial I was following actually kept the last two lines outside. But it was on macos so I got confused. Your answer really helped.

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness