GithubHelp home page GithubHelp logo

gitvipin / pali Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6.74 MB

A simple Thread Pool library in Python

Home Page: https://pypi.org/project/pali/

License: Other

Python 99.11% Shell 0.89%
python3 thread-pool pipeline-framework

pali's Introduction

Downloads

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!

pali's People

Contributors

gitvipin avatar

Watchers

 avatar

pali's Issues

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.