Multi processes

sir,
I am not getting output for proc.start() . as soon as I execute this statement no output will be shown in the Jupyter notebook as mentioned in lec

hey @palashrai31 ,
can you please share your code and a screenshot of your output.
Thank You :slightly_smiling_face:.

From multiprocessing import Process
Def square(n):
Prin(n**2)
Procs=[ ]
For i in range(5):
Procs.append(Process(target = square, args = (i+1,)
For proc in range procs:
Proc.start( )

it’s print* only ,there in the function "square "

can you please run
import multiprocessing
print(multiprocessing.cpu_count())

and let me know what does it shows as output

yeah , it is showing 8 as the output

try restarting your kernel and also , once try to run all this code in a single cell.
Sometimes it happens.

sir, still not getting an output, also tried to run the whole code in a single cell.

just for checking can you please also run this code in a .py file from the command prompt , and let me know the output .

Thank You.

RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if name == ‘main’: freeze_support() … The “freeze_support()” line can be omitted if the program is not going to be frozen to produce an executable.RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if name == ‘main’: freeze_support() … The “freeze_support()” line can be omitted if the program is not going to be frozen to produce an executable.

it shouldn’t be like this.
okay.

You were running this code in local jupyter notebook or were using any other editor for it .
Like PyCharm or VScode , anyone else.

I am running this using Pycharm actually

That might be a problem.
Because for me too , it doesn’t work in VScode but running in local jupyter notebook it works.

Can you please try this on local jupyter notebook?

i also tried to run .py file in Jupyter but neither I am getting any output nor an error.

.py file in jupyter ? How?

just run jupyter notebook from cmd , ( if it is installed then it will open a home page on browser else you will need to download it )
then create a new notebook and the run the same code as you run the first time.
and remember to close the pycharm first and anyother application also that is using python.

Actually may be there is some error with the system only oi guess coz it run perfectly on Colab.

okay i will try to do that too if i get the output i will let you know . moreover i got the concept and the output too on colab so its okay . Thanks

yeah thats the only reason.
because while you are running it on PyCharm , there are multiple other processes too running in background and hence due to them you are not able to run yours.

thats Nice.

No Problem.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.