[Python-ideas] ThreadPool worker function
Luca Sbardella
luca.sbardella at gmail.com
Mon Jun 3 12:51:55 CEST 2013
While using the ThreadPool in the multiprocessing.pool module, I needed to
use a different implementation for the *worker* function. Since there is no
way to overwrite it directly, I'm overwriting the Process attribute with a
method:
def myworker(...):
...
class ThreadPool(pool.ThreadPool):
def Process(self, target=None, **kwargs):
return Thread(target=myworker, **kwargs)
which is good enough, works for 2.6 and up.
On the other hand, *worker* could be defined as a class attribute in the
same way as the Process.
Something like this:
def default_worker(...):
...
class Pool(object):
Process = Process
worker = default_worker
...
Less verbose and less of a hack IMO.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130603/25b23ec6/attachment.html>
More information about the Python-ideas
mailing list