I wrote a program using threads but as it is CPU intensive, threading really isn't giving any performance boost so i started looking into multiprocessing. All my code uptill now has been written keeping in mind that two threads can work on the same global variables but that isn't possible with multiprocessing as far as i know.
Is there any way to do something like this without rewriting my whole code?
I just need to do some calculations and change the values of a few variables in the second process.
a simple example for what i intend to achieve:
target=list()
queue=list()
def func(a,b,target):
temp=list()
for i in range(0,a):
for j in range(0,b)
temp.append('a'+str(i)+'b'+str(j))
target=list()
def process_func():
go=True
while go:
target_=queue.pop(0)
func(target[0],target[1],target[2])
if __name__=='__main__':
p=multiprocessing.Process(target=process_func)
p.start()
A main function will be adding lists to the queue. I can't figure out how to do something like this. My main aim is to just do this in a way that results in minimal changes to my existing code.
What i though i could do was use the queues from the multiprocessing module but i don't understand how exactly to implement them as the tutorials I could find would have resulted in changing my code a lot.