duedue / ThreadPool

A simple thread pool for python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread pool

This is a simple thread pool for python(using queue module).

Install:

    python setup.py install

Usage:

  • Firstly, you should define a callback to deal with your task.

      def do_work(*args, **kwds):
          # do something
    
  • Then, you can create a thread pool to schedule your tasks.

      from threadpool import ThreadPool
      # Create thread pool with nums threads
      pool = ThreadPool(nums)
      # Add a task into pool
      pool.add_task(task_name, do_work, args, kwds)
    
      # Get result from result pool
      result = pool.get_task_result(task_name)
      
      # Get all results from result pool
      results = pool.get_all_task_result(task_name)
      
      # Join and destroy all threads
      pool.destroy()
    

About

A simple thread pool for python


Languages

Language:Python 100.0%