I'm creating processes using multiprocessing
in Python, but I need to create processes inside other processes, that is, child processes. Is it possible to do this using multiprocessing
?
Code:
import time
import multiprocessing
def calc_square():
while 1:
time.sleep(1)
print("square: %i" %(3*3*3))
def calc_cube():
while 1:
time.sleep(1)
print("cube: %i" %(2*2*2))
p2 = multiprocessing.Process(target=calc_square)
p2.start()
p2.join()
if __name__ == '__main__':
p1 = multiprocessing.Process(target=calc_cube)
p1.start()
p1.join()
When creating the calc_cube
process, it gives print
to cube
once and creates the calc_square
process, and only shows the print
of calc_square
, ie the two processes do not run in parallel.
Is it possible to run in parallel?