Monday, 30 September 2013

Python Multiprocessing: Ending an infinite counter

Python Multiprocessing: Ending an infinite counter

I'm new to multiprocessing, and I'm just trying to write a simple program
in Python 3.2 which has a counter increasing indefinitely in one thread,
while a second thread checks to see if a given value has been reached in
the first thread. Once the value is reached, I would like the
multiprocessing thread to close, and for the program to display a "Process
Complete" statement.
As far as I understand it, the program would look something like (where
the given value is 10):
import multiprocessing as mp
def Counter():
i=1
while i > 0:
print("i: ",i)
i+=1
def ValueTester(i):
if i >= 10:
*End Counter Function Thread*
if __name__ == '__main__':
*Begin multiprocessing, one thread for "Counter" and a second for
"ValueTester"*
print("Process Complete")
I apologise for the vagueness of the psuedocode; I have read the Python
documentation alongside several different examples, and I can't seem to
find a simple solution.
Additionally, once this is working, how would I go about setting the given
stopping value (i.e. passing a variable to ValueTester, rather than just
using 10)?
Thank you very much for your help.

No comments:

Post a Comment