Created
March 28, 2014 15:47
-
-
Save chancyk/9835905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import os | |
import time | |
import Queue | |
def scoring_function_dummy(jobs, results): | |
while True: | |
try: | |
task = jobs.get(True, 1) | |
print '%s: working: %s' % (os.getpid(), task) | |
results.put(task) | |
jobs.task_done() | |
except Queue.Empty: | |
print '%s: block timeout' % os.getpid() | |
break | |
if __name__ == '__main__': | |
Q = multiprocessing.JoinableQueue() | |
R = multiprocessing.Queue() | |
processes = [multiprocessing.Process(target=scoring_function_dummy, args=(Q,R)) | |
for i in range(4)] | |
for process in processes: | |
process.start() | |
Q.put(1) | |
Q.put(2) | |
Q.put(3) | |
time.sleep(0.5) | |
Q.put(4) | |
Q.put(5) | |
Q.put(6) | |
Q.join() | |
for process in processes: | |
process.join() | |
# Concat the results queue... | |
print 'Complete.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment