A simple ThreadPool library
Project description
Pali
Pali is a simple Thread Pool library for Python. It is compatible with Python3 as well as Python2.
Pali can be used for:
- Creating Data Pipelines.
- Handling requests in Messaging Brokers (on the top of TCP/IP layer).
- Simulating any stress testing systems.
- API Testing systems.
Usage
Pali is simple to use. Pali's Worker Pool works on tasks with well defined interface in pali.task.Task
.
New Tasks can be extended from it as following. _run
method is important and mandatory to define as the
Thread Pool internally looks and invokes this function as start of the task.
>>> from pali import worker, task
>>> class MyTask(task.Task):
... def __init__(self, ident):
... self.task_id = ident
... self.done = False
...
... def _run(self):
... self.done = True
Thread Pool in itself can work either as context manager or can be invoked manually. Example below shows it's use as context manager.
# create 10 tasks
>>> tasks = [MyTask(i) for i in range(10)]
# Start a Thread Pool with 3 thread and push tasks on it.
# Tasks are processed as and when they come.
>>> with worker.ThreadPool(3) as tpool:
... _ = [tpool.append_task(t) for t in tasks]
# Check the status of Tasks
>>> status = [t.done for t in tasks]
>>> status
[True, True, True, True, True, True, True, True, True, True]
Further examples can be found at https://github.com/gitvipin/Pali/tree/master/tests that reflect different ways of using ThreadPool.
Requirements
Python 2.7+ and Python 3.4+
Share and enjoy!
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
Built Distribution
File details
Details for the file pali-0.0.7.tar.gz
.
File metadata
- Download URL: pali-0.0.7.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 628570ea2c733da4176ff3a574f30cb07f19c6d35e79cead00a950fc6926c4a9 |
|
MD5 | 4f2be12bcda316e663a4d8385923dad8 |
|
BLAKE2b-256 | eef547e9b60c3c6c3e4f58ef2808ddf73f950abfee6e595da36bbaa562e19044 |
File details
Details for the file pali-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: pali-0.0.7-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 478f0c3c555299dbd41fcc5c07622b821289c4a2d704c9046d22b68efc1dd274 |
|
MD5 | 36b8c154a7039ead5f0c2aff288bf232 |
|
BLAKE2b-256 | d0644b8f36478e745eb4809c9b0be71bdb2cb1576a8e85ef983a4caa16fae2db |