124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | |
def dispatch(self, func, *args, **kwargs): |
""" return Reply object for the asynchronous dispatch |
of the given func(*args, **kwargs) in a |
separate worker thread. |
""" |
if self._shuttingdown: |
raise IOError("WorkerPool is already shutting down") |
try: |
thread, _ = self._ready.popitem() |
except KeyError: |
if self.maxthreads and len(self._alive) >= self.maxthreads: |
raise IOError("can't create more than %d threads." % |
(self.maxthreads,)) |
thread = self._newthread() |
return thread.send((func, args, kwargs)) | |