A simple threadpool
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitignore
MANIFEST
README.md
iter.sh
setup.py
simple_threadpool.py
test.py

README.md

Intro

simple_threadpool: a simple threadpool

Install

pip install simple_threadpool

Usage

import random, time
from threading import current_thread
from simple_threadpool import ThreadPool


def my_worker(arg):
  '''
  custom worker
  '''
  time.sleep(random.random())
  print '%s: ' % current_thread().name, arg + 1


# create a ThreadPool instance with 4 Threads and a callback
tp = ThreadPool(4, my_worker)

# produce and send some data to the pool
print 'First round:'
tp.feed([1, 2, 3, 4, 5])

# you can feed any times
print 'Second round:'
tp.feed([6, 7, 8, 9, 0])

# close the queue
tp.close()