collapsing-thread-pool-executor-「線程池」是一個與線程池兼容的線程池。-Edward Beech How to install How to develop Ex...

collapsing-thread-pool-executor-「線程池」是一個與線程池兼容的線程池。-Edward Beech

發佈:2020-12-23 14:16:45.497853

做者:Edward Beech

做者郵箱:initialed85@gmail.com

首頁:https://github.com/initialed85/collapsing-thread-pool-executor

文檔:None

下載連接

CollapsingThreadPoolExecutor

The CollapsingThreadPoolExecutor is inspired by and compatible with the ThreadPoolExecutor from the "futures" module, it operates differently in that worker threads are handled with a stack which results in the same worker or workers doing all the work (and idle workers being destroyed).python

How to install

$ pip install collapsing-thread-pool-executor

How to develop

Prerequisitesgit

  • python3 w/ pip
  • python2 w/ pip
  • virtualenvwrapper
  • entr

Set up the environmentsgithub

$ mkvirtualenv -p `which python2.7` collapsing-thread-pool-executor-py2
$ pip install .
$ pip install -r requirements.txt

$ mkvirtualenv -p `which python3` collapsing-thread-pool-executor-py3
$ pip install .
$ pip install -r requirements.txt

Watch the testsapp

# watch python2 tests in one window
$ workon collapsing-thread-pool-executor-py2
$ find ./ -name '*.py' | entr -c py.test -v --log-level=DEBUG collapsing_thread_pool_executor

# watch python3 tests in one window
$ workon collapsing-thread-pool-executor-py3
$ find ./ -name '*.py' | entr -c py.test -v --log-level=DEBUG collapsing_thread_pool_executor

Examples

The example below will execute some_task() 100 times; as some_task() should take a second to execute and as we've allocated 10 workers, the whole thing should take about 10 seconds.python2.7

import time

from collapsing_thread_pool_executor import CollapsingThreadPoolExecutor

def some_task():
    time.sleep(1)

# all arguments are optional
pool = CollapsingThreadPoolExecutor(
    workers=10,
    thread_name_prefix='SomePool',
    permitted_thread_age_in_seconds=60,
)

for i in range(0, 100):
    pool.submit(some_task)





 Copy from pypi.org

查詢時間:7.513ms
渲染時間:7.642ms

本文同步分享在 博客「zhenruyan」(other)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。ui

相關文章
相關標籤/搜索