Giter Club home page Giter Club logo

threadlist's Introduction

threadlist

A thread loop "limiter" module for Python.

More details using:

import threadlist
help(threadlist)

ThreadList

An extended Python list to handle (and limit) thread executions.

When you run many slow threading.Thread() instances, you can reach the maximum number of thread your system can support. This special list provide some controls on how threads are started.

The way threads are handles by this list is time based. This is efficient for slow threads (slower than 0.1 sec) but can be less efficient on multiple very fast threads.

import threading
from threadlist import ThreadList, TimeoutError

threads = ThreadList()
for _ in xrange(10):
    thread = threading.Thread()
    threads.append(thread)
threads.max_count = 4
threads.total_timeout = 15
try:
    threads.run() # wait until every thread is terminated
except TimeoutError:
    print "Threads Timeout reached!"

A typical big images conversion example:

import threading, multiprocessing
from threadlist import ThreadList

image_paths # a huge list of image file to convert

threads = ThreadList()
for image_path in image_paths:
    thread = SlowConversionThread(image_path)
    threads.append(thread)
threads.max_count = multiprocessing.cpu_count()
threads.start()
# continue your script here...
threads.join()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.