Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BrianPugh/lox

Repository files navigation

assets/lox_200w.png

https://travis-ci.com/BrianPugh/lox.svg?branch=master Documentation Status Updates

Threading and multiprocessing made easy.

Lox provides decorators and synchronization primitives to quickly add concurrency to your projects.

Installation

pip3 install --user lox

Features

  • Multithreading: Powerful, intuitive multithreading in just 2 additional lines of code.
  • Multiprocessing: Truly parallel function execution with the same interface as multithreading.
  • Synchronization: Advanced thread synchronization, communication, and resource management tools.

Todos

  • All objects except lox.process are for threads. These will eventually be multiprocess friendly.
  • Chaining of scatter calls to multiple worker pools

Usage

Easy Multithreading

>>> import lox
>>>
>>> @lox.thread(4) # Will operate with a maximum of 4 threads
... def foo(x,y):
...     return x*y
>>> foo(3,4) # normal function calls still work
12
>>> for i in range(5):
...     foo.scatter(i, i+1)
-ignore-
>>> # foo is currently being executed in 4 threads
>>> results = foo.gather() # block until results are ready
>>> print(results) # Results are in the same order as scatter() calls
[0, 2, 6, 12, 20]

Easy Multiprocessing

>>> import lox
>>>
>>> @lox.process(4) # Will operate with a pool of 4 processes
... def foo(x,y):
...     return x*y
>>> foo(3,4) # normal function calls still work
12
>>> for i in range(5):
...     foo.scatter(i, i+1)
-ignore-
>>> # foo is currently being executed in 4 processes
>>> results = foo.gather() # block until results are ready
>>> print(results) # Results are in the same order as scatter() calls
[0, 2, 6, 12, 20]

About

Threading and Multiprocessing made easy.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •