summaryrefslogtreecommitdiffstats
path: root/Doc/includes/mp_workers.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/includes/mp_workers.py')
-rw-r--r--Doc/includes/mp_workers.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/Doc/includes/mp_workers.py b/Doc/includes/mp_workers.py
index 3b92269..e64a156 100644
--- a/Doc/includes/mp_workers.py
+++ b/Doc/includes/mp_workers.py
@@ -1,3 +1,16 @@
+#
+# Simple example which uses a pool of workers to carry out some tasks.
+#
+# Notice that the results will probably not come out of the output
+# queue in the same in the same order as the corresponding tasks were
+# put on the input queue. If it is important to get the results back
+# in the original order then consider using `Pool.map()` or
+# `Pool.imap()` (which will save on the amount of code needed anyway).
+#
+# Copyright (c) 2006-2008, R Oudkerk
+# All rights reserved.
+#
+
import time
import random
@@ -55,9 +68,9 @@ def test():
Process(target=worker, args=(task_queue, done_queue)).start()
# Get and print results
- print('Unordered results:')
+ print 'Unordered results:'
for i in range(len(TASKS1)):
- print('\t', done_queue.get())
+ print '\t', done_queue.get()
# Add more tasks using `put()`
for task in TASKS2:
@@ -65,7 +78,7 @@ def test():
# Get and print some more results
for i in range(len(TASKS2)):
- print('\t', done_queue.get())
+ print '\t', done_queue.get()
# Tell child processes to stop
for i in range(NUMBER_OF_PROCESSES):