Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
.. image:: https://raw.githubusercontent.com/BrianPugh/lox/main/assets/lox_200w.png
.. image:: https://img.shields.io/pypi/v/lox.svg :target: https://pypi.python.org/pypi/lox
.. image:: https://circleci.com/gh/BrianPugh/lox.svg?style=svg :target: https://circleci.com/gh/BrianPugh/lox
.. image:: https://readthedocs.org/projects/lox/badge/?version=latest :target: https://lox.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
Threading and multiprocessing made easy.
Lox provides decorators and synchronization primitives to quickly add concurrency to your projects.
pip3 install --user lox
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.
lox.process
are for threads. These will eventually be multiprocess friendly.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]
Or, for example, if you aren't allowed to directly decorate the function you would like multithreaded/multiprocessed, you can just directly invoke the decorator:
.. code-block:: pycon
>>> # Lets say we don't have direct access to this function
... def foo(x, y):
... return x * y
...
>>>
>>> def my_func():
... foo_threaded = lox.thread(foo)
... for i in range(5):
... foo_threaded.scatter(i, i + 1)
... results = foo_threaded.gather()
... # foo is currently being executed in default 50 thread executor pool
... return results
...
This also makes it easier to dynamically control the number of thread/processes in the executor pool. The syntax is a little weird, but this is just explicitly invoking a decorator that has optional arguments:
.. code-block:: pycon
>>> # Set the number of executer threads to 10
>>> foo_threaded = lox.thread(10)(foo)
Easy Multiprocessing ^^^^^^^^^^^^^^^^^^^^
.. code-block:: pycon
>>> 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]
Progress Bar Support (tqdm) ^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: pycon
>>> import lox
>>> from random import random
>>> from time import sleep
>>>
>>> @lox.thread(2)
... def foo(multiplier):
... sleep(multiplier * random())
...
>>> for i in range(10):
>>> foo.scatter(i)
>>> results = foo.gather(tqdm=True)
90%|████████████████████████████████▌ | 9/10 [00:03<00:00, 1.32it/s]
100%|███████████████████████████████████████| 10/10 [00:06<00:00, 1.46s/it]
LOX_DEBUG
is set to a true-like value (true
, 1
, etc.). Makes it easier to set breakpoints in multithreaded code without having to manually edit the decorator.@lox.thread(0)
. This will execute scatter
calls in parent thread.
Useful for debugging breakpoints in parallelized code.tqdm
support on lox.process.gather
. See v0.8.0 release notes for usage.tqdm
support on lox.thread.gather
Can be a bool::
>>> my_func.gather(tqdm=True)
Can be a tqdm
object::
>>> from tqdm import tqdm
>>> pbar = tqdm(total=100)
>>> for _ in range(100):
>>> my_func.scatter()
>>> my_func.gather(tqdm=pbar)
lox.process
.lox.Announcement
subscribe()
calls now return another Announcement
object that behaves like a queue instead of an actual queue. Allows for
many-queue-to-many-queue communications.
New Object: lox.Funnel
. allows for waiting on many queues for a complete
set of inputs indicated by a job ID.
New Object: lox.Announcement
. Allows a one-to-many thread queue with
backlog support so that late subscribers can still get all (or most recent)
announcements before they subscribed.
New Feature: lox.thread
scatter
calls can now be chained together.
scatter
now returns an int
subclass that contains metadata to allow
chaining. Each scatter call can have a maximum of 1 previous scatter
result.
Documentation updates, theming, and logos
Multiprocessing decorator. lox.pool renamed to lox.thread
Substantial pytest bug fixes
Documentation examples
timeout for RWLock
Added QLock
Documentation syntax fixes
FAQs
Threading and Multiprocessing for every project.
We found that lox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.