I just want to run an example from this site which is the following code:
from multiprocessing import Process
def square(x):
for x in numbers:
print('%s squared is %s' % (x, x**2))
if __name__ == '__main__':
numbers = [43, 50, 5, 98, 34, 35]
p = Process(target=square, args=('x',))
p.start()
p.join()
print ("Done")
it says that if you run the code, you should see the following results:
#result
Done
43 squared is 1849
50 squared is 2500
5 squared is 25
98 squared is 9604
34 squared is 1156
35 squared is 1225
But as I run this code, I just see Done in results and nothing more. In that Tutorial used Python 2.7 but I have 3.6 and I added () in prints.
Thank you for your help
p.join()(notice the brackets afterjoin()) to wait for the process to finish. Also, in case you didn't make an error when indenting your code on SO, keep in mind that indentation is very important in Python.p.join()just ensures main process waits for children to finish. So you would seeDoneat the end instead of first print as shown in output by OP. Are you indentations correct? When I ran the same code on my python 3.5.2, it works nicely.()is added, it was typo. But i do not know why it does not work in my python 3.6.3. I just seeDone