Skip to main content

Thread Pool for Python 2 and 3

Project description

It supports py2 and py3

Thread Pool for python 2 (and 3) with multiple parameters. Python2 include an undocumented thread pool which only accept functions with single arguments. TPool implements a pool for threads supporting multiple arguments

Install

pip install TPool

Why not PPool

If you want to have access to shared variables. But also note that in Python (at least the cPython version) include a global lock that it does not run multiple threads at the same time, but it is good enough if the bottle neck is disk IO or network.

Example

from TPool.TPool import Pool
from threading import Lock

pairs = []


def foo_merge(name, num, lock):
    global pairs
    lock.acquire()
    pairs.append((name, num))
    lock.release()


def example():
    global pairs
    pairs = []
    lock = Lock()
    local_pairs = [('A', 2), ('B', 3), ('C', 4), ('D', 5)]
    params = []
    for p in local_pairs:
        param = p + (lock,)
        params.append(param)
    pool = Pool(max_num_of_threads=3, func=foo_merge, params_list=params)
    pool.run()
    print pairs


if __name__ == "__main__":
    example()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TPool-1.3.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

TPool-1.3-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page