Add WORKER_POOL environmental option to facilitate pysawsim.manager benchmarking.
[sawsim.git] / pysawsim / manager / thread.py
index 7c62db091024c7af92fff18feda9b65cc71e4a92..a4e98f5cf5a0b508c520b713c4b644616ecb4ae5 100644 (file)
@@ -21,6 +21,7 @@
 """
 
 import copy
+import os
 from Queue import Queue, Empty
 import threading
 
@@ -82,7 +83,7 @@ class ThreadManager (JobManager):
     threads to a single core.  See the following discussions:
 
     * http://smoothspan.wordpress.com/2007/09/14/guido-is-right-to-leave-the-gil-in-python-not-for-multicore-but-for-utility-computing/
-    * http://docs.python.org/faq/library#id18
+    * http://docs.python.org/faq/library#can-t-we-get-rid-of-the-global-interpreter-lock
     * http://www.artima.com/weblogs/viewpost.jsp?thread=214235
     * http://www.snaplogic.com/blog/?p=94
     * http://stackoverflow.com/questions/31340/
@@ -90,7 +91,7 @@ class ThreadManager (JobManager):
     Increasing `worker_pool` will only help you get around IO blockin
     at the cost increased time-slicing overhead.
     """
-    def __init__(self, worker_pool=2):
+    def __init__(self, worker_pool=None):
         super(ThreadManager, self).__init__()
         self._blocked = []
         self._setup_queues()
@@ -101,6 +102,8 @@ class ThreadManager (JobManager):
         self._receive_queue = Queue()
 
     def _spawn_workers(self, worker_pool):
+        if worker_pool is None:
+            worker_pool = int(os.environ.get('WORKER_POOL', 2))
         self._workers = []
         for i in range(worker_pool):
             worker = WorkerThread(spawn_queue=self._spawn_queue,