In my code I have two functions, the first function operate_camera
updates the storage variable. The second function print_func
prints the storage variable.
I would like to run these two functions concurrently, with the printing process happening with a delay of 15 seconds. However the operate_camera
function contains a while
loop. And by running the script, it will only run the process p2
once, and will stay stuck at the process p1
.
For simplicity, I work with simple 1D arrays in the following code.
from multiprocessing import Process, Array
import numpy as np
import time
def operate_camera(store):
while True: # loop that updates image
store = store + np.ones_like(store)
def print_func(store):
print(store)
time.sleep(15)
if __name__ == "__main__":
store = np.array([0,0,0])
p1 = Process(target=operate_camera, args=(store,))
p2 = Process(target=print_func, args=(store,))
p1.start()
p2.start()
The output will simply be stuck at
[0,0,0]
Are there any solutions within the multiprocessing package that can allow me to retain this form of code. If not, are there any alternative solutions to this problem?