MCPcopy Create free account
hub / github.com/ActiveState/code / __init__

Method __init__

recipes/Python/576519_Thread_pool_same_API/recipe-576519.py:95–112  ·  view source on GitHub ↗

\param nworkers (integer) number of worker threads to start \param name (string) prefix for the worker threads' name

(self, nworkers, name="Pool")

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

terminateMethod · 0.95
xrangeClass · 0.85
PoolWorkerClass · 0.85
startMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected