Why doesn't this print statement work? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why doesn't this print statement work? (/thread-33029.html) Pages:
1
2
|
Why doesn't this print statement work? - stylingpat - Mar-23-2021 Hey guys, I'm learning about multiprocessing. If I run this code, I don't get the print "Sleeping for 1 second". But if I run the line do_something(), I'll get both prints. Any reason why? It doesnt do it with Anaconda or IDLE. import multiprocessing import time start = time.perf_counter() def do_something(): print('Sleeping for 1 second') time.sleep(1) print('Done sleeping...') if __name__ == '__main__': p1 = multiprocessing.Process(target=do_something) p2 = multiprocessing.Process(target=do_something) p1.start() p2.start() p1.join() p2.join finish = time.perf_counter() print(f'Finished in {round(finish-start,4)} seconds')Here's my outputs
RE: Why doesn't this print statement work? - buran - Mar-23-2021 I get
RE: Why doesn't this print statement work? - stylingpat - Mar-23-2021 Yeah thats what the guy gets on the video? Why wouldnt I get that? So I just ran it in the terminal and I get the same thing as you now.. but running it in idle or anaconda I dont get it? What would be different? RE: Why doesn't this print statement work? - buran - Mar-23-2021 for IDLE check https://stackoverflow.com/q/35293178/4046632 I don't use IDLE or anaconda, but there are multiple issues/posts about it if you google it. RE: Why doesn't this print statement work? - stylingpat - Mar-23-2021 This is my v3.9 IDLE This is my v3.8 Virtual Enviroment using IDLE This is my v3.8 Virtual Enviroment using Anaconda This is what I get in my Anaconda Prompt 3.9 And Anaconda Prompt 3.8 Why would the two prompts be any different from the applications?
RE: Why doesn't this print statement work? - buran - Mar-23-2021 Did you check the link in my previous post? It explains why it does not work when start IDLE from icon (vs. starting from cmd). Also https://bugs.python.org/issue11820 For IPython I think this is helpful https://stackoverflow.com/questions/23641475/multiprocessing-working-in-python-but-not-in-ipython Again - it is known limitation RE: Why doesn't this print statement work? - stylingpat - Mar-23-2021 Awesome thank you so much, I'll go through the pages. Sorry alot of the stuff on stackoverflow just goes way over my head.. RE: Why doesn't this print statement work? - stylingpat - Mar-23-2021 Like this stuff.. I just cannot comprehend class classname: def createname(self, name): self.name = name; def displayname(self): return self.name; def saying(self): print("Hello %s" % self.name); first = classname; second = classname; first.createname("Bobby");I undersstand the idea, but all the "names" or "labels" of everything is way to similar.. I need this example, with like a pizza and different toppings, cheese, mushrooms, onions... seperate looking words. I feel like everytime I goto stack overflow, its just that.. RE: Why doesn't this print statement work? - buran - Mar-23-2021 First of all this is very poor example of python code (i.e. unpythonic) and of implementation of custom class in python in particular. But I would suggest you get familiar with fundamentals before you go into more complex things like class RE: Why doesn't this print statement work? - stylingpat - Mar-23-2021 Its kinda funny thinking about this now, how I can't look at that yet and understand it. That block of code is a blur to my eyes and brain. Its not because its intellectually out of reach, that my brain cant process the connections. Its the way its presented. Everything in that block of code is too similar. Its made me realize where my success in life has come from. I'm not super smart, like raw mental mathematical processing smart.. I just have an infinite amount of patience when it comes to learning something. Its pretty cool to see how far that has gotten me! Maybe I'll sit down tonight, proper sit down and tackle that block of code LOL |