Reputation: 1321
I am currently running a program that has a robot shifting piles of "beepers".
I want to be able to return a value from a function while also running that function. When I run the function, it stops the program. I'm using a module called pyKarel which is creates a robot and beepers. count_beepers_1_1 and count_beepers_2_1 are global variables, and count_beepers_1 and count_beepers_2 are local variables that are defined within the shiftPiles
method. I want to save over the local variables into the global variables. Here is my code
def shiftPiles(arg, count_beepers_1, count_beepers_2):
#shift the piles of beepers
return count_beepers_1, count_beepers_2
while piles > 0:
count_beepers_1_1, count_beepers_2_2 = shiftPiles(bob, count_beepers_1_1, count_beepers_2_1)
Upvotes: 0
Views: 95
Reputation: 77857
You've pretty well defined the problem: you want two chunks of code to execute simultaneously, and a function call doesn't do that.
This is a classic application for multiprocessing. Python has support packages for multiple processes, multiple threads (should you determine that you can use that as well).
Also look at the possibility of using a generator -- a "function" that yields one value on each call, but each successive call starts where the last one left off.
Upvotes: 1