
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Generic Python Decorators for use in any project.
generic-decorators
is released to public PyPI - generic-decorators. It can be installed using this command:
pip install generic-decorators
make_parallel
Summary: runs function in parallel instead of sequencial for loop.
Example
Parallel trigger of functions sample_function
with 1 param list_of_post_ids
using make_parallel
decorator and equivalent sequential trigger using for loop
.
def parallel_function_trigger():
list_of_post_ids = list(range(1, 20))
return make_parallel(sample_function)(list_of_post_ids)
#equivalent sequencial version
def serial_function_trigger():
list_of_post_ids = list(range(1, 20))
# Serial way of calling the function
results = []
for post_id in list_of_post_ids:
res = sample_function(post_id)
results.append(res)
return results
You can use below timing decorator to compare time of above parallel and sequential versions.
make_parallel_processes
Description: Similar functionality like make_parallel but
uses mulitprocessing
instead of threading
.
Example
def parallel_function_trigger():
list_of_post_ids = list(range(1, 20))
return make_parallel_processes(sample_function)(list_of_post_ids)
timing
Summary: calculate and print how much time function processing took.
Example
@timing
def sleep_n_seconds(n: int):
time.sleep(n)
sleep_n_seconds(5)
It should print something like this (time can differ):
func:'sleep_n_seconds' args:[(5,), {}] took: 5.0047 sec
singleton
Summary: make class Singleton - class which will have max 1 instance created
Example
@singleton
class MyClass(object):
"""docstring for MyClass"""
def __init__(self):
pass
for i in range(0, 10):
obj = MyClass()
print(obj)
It should print something like this (all objects of class are the same):
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
FAQs
Generic Python Decorators for use in any project
We found that generic-decorators 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.