Add WORKER_POOL environmental option to facilitate pysawsim.manager benchmarking.
[sawsim.git] / pysawsim / manager / thread.py
index 48a2f9fec3b0f97315c18dc787cc513423f00851..a4e98f5cf5a0b508c520b713c4b644616ecb4ae5 100644 (file)
@@ -21,6 +21,7 @@
 """
 
 import copy
+import os
 from Queue import Queue, Empty
 import threading
 
@@ -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,