A simple ThreadPool library
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.
Pali is simple to use. Pali's Worker Pool works on tasks with well defined interface in
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 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 os using ThreadPool.
Python 2.7+ and Python 3.4+
Share and enjoy!
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pali-0.0.1-py3-none-any.whl (11.4 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size pali-0.0.1.tar.gz (5.4 kB)||File type Source||Python version None||Upload date||Hashes View hashes|