\param nworkers (integer) number of worker threads to start \param name (string) prefix for the worker threads' name
(self, nworkers, name="Pool")
| 93 | """ |
| 94 | |
| 95 | def __init__(self, nworkers, name="Pool"): |
| 96 | """ |
| 97 | \param nworkers (integer) number of worker threads to start |
| 98 | \param name (string) prefix for the worker threads' name |
| 99 | """ |
| 100 | self._workq = Queue.Queue() |
| 101 | self._closed = False |
| 102 | self._workers = [] |
| 103 | for idx in xrange(nworkers): |
| 104 | thr = PoolWorker(self._workq, name="Worker-%s-%d" % (name, idx)) |
| 105 | try: |
| 106 | thr.start() |
| 107 | except: |
| 108 | # If one thread has a problem, undo everything |
| 109 | self.terminate() |
| 110 | raise |
| 111 | else: |
| 112 | self._workers.append(thr) |
| 113 | |
| 114 | def apply(self, func, args=(), kwds=dict()): |
| 115 | """Equivalent of the apply() builtin function. It blocks till |
nothing calls this directly
no test coverage detected