From bf6fb65bc488939833fb7794ca072e974b88f919 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Sun, 5 Feb 2012 09:42:07 -0800 Subject: [PATCH] Things working: next step -- enqueue doubler, tripler, negator --- test/parallel.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/parallel.py b/test/parallel.py index c5e930e7..dfa636aa 100644 --- a/test/parallel.py +++ b/test/parallel.py @@ -16,7 +16,6 @@ We will take this in steps by first writing toy models and filling them out """ def doubler(n): - result = 2*n return 2*n def negator(n): @@ -25,9 +24,6 @@ def negator(n): def tripler(n): return 3*n -def totaler(n, results): - result = doubler(n) + negator(n) + tripler(n) - results.put((n, result)) class Consumer(multiprocessing.Process): @@ -53,11 +49,11 @@ class Consumer(multiprocessing.Process): return -class Task(object): +class NetTask(object): def __init__(self, n): self.n = n def __call__(self): - time.sleep(0.1) # pretend to take some time to do the work + #time.sleep(0.1) # pretend to take some time to do the work result = doubler(self.n) + negator(self.n) + tripler(self.n) return (self.n, result) def __str__(self): @@ -81,7 +77,7 @@ def main(): # create a separate process for each totaler operation for k in xrange(n_tasks): - tasks.put(Task(k)) + tasks.put(NetTask(k)) # Add a poison pill for each consumer for i in xrange(num_consumers):