A python module of useful decorators
Project description
=======
Deckor
=======
Decorate your functions and with 'deckor'ators. A module created while learning decorators.
Installation
=============
pip install deckor
Decorators Supported:
======================
* timer : Measure execution time of functions
@deckor.timer
def fact(x):
if x <= 0:
return 1
return x*fact(x-1)
* cacheit : Cache intermediate results
@deckor.cacheit
def fact(x):
if x <= 0:
return 1
return x*fact(x-1)
* trace : Print the pretty recursion trace
@deckor.trace
def fib(x):
if x < 2:
return x
return fib(x-1)+fib(x-2)
fib(10)
Now, try trace with cacheit
@deckor.cacheit
@deckor.trace
def fib(x):
if x < 2:
return x
return fib(x-1)+fib(x-2)
fib(10)
* with_retries : function signature: with_retries(tries=5, delay=0, increment=0). Try execution of function with retries. Retry'tries' no of times. Delay of 'delay' seconds between retries. Increase the delay by 'increment' between retries
@with_retries(5)
def random_f():
try: r = requests.get("random")
except: return
* syncronize : Provides very basic syncronization. Note: Not free from race condition only for basic usage
import threading
lock = threading.Lock()
sample_list = []
@deckor.syncronize(lock)
def sample(sample_list):
sample_list.append(1)
#sample list is modified only after lock is acquired
#so, mdification is sample_list os thread safe
Deckor
=======
Decorate your functions and with 'deckor'ators. A module created while learning decorators.
Installation
=============
pip install deckor
Decorators Supported:
======================
* timer : Measure execution time of functions
@deckor.timer
def fact(x):
if x <= 0:
return 1
return x*fact(x-1)
* cacheit : Cache intermediate results
@deckor.cacheit
def fact(x):
if x <= 0:
return 1
return x*fact(x-1)
* trace : Print the pretty recursion trace
@deckor.trace
def fib(x):
if x < 2:
return x
return fib(x-1)+fib(x-2)
fib(10)
Now, try trace with cacheit
@deckor.cacheit
@deckor.trace
def fib(x):
if x < 2:
return x
return fib(x-1)+fib(x-2)
fib(10)
* with_retries : function signature: with_retries(tries=5, delay=0, increment=0). Try execution of function with retries. Retry'tries' no of times. Delay of 'delay' seconds between retries. Increase the delay by 'increment' between retries
@with_retries(5)
def random_f():
try: r = requests.get("random")
except: return
* syncronize : Provides very basic syncronization. Note: Not free from race condition only for basic usage
import threading
lock = threading.Lock()
sample_list = []
@deckor.syncronize(lock)
def sample(sample_list):
sample_list.append(1)
#sample list is modified only after lock is acquired
#so, mdification is sample_list os thread safe
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
deckor-0.0.1.tar.gz
(2.3 kB
view details)
File details
Details for the file deckor-0.0.1.tar.gz
.
File metadata
- Download URL: deckor-0.0.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
28b026c6e238c5315cbdc216492bb68a83d1809111daa967fad99030fb1574d9
|
|
MD5 |
71884cefc5b4c6c4e90bd201189c68fc
|
|
BLAKE2b-256 |
652d6f2c6bc21795ee46579a786ffb79472a9041a3e74ffe9be30956a3a4fe5b
|