qaviton handlers
Project description
Qaviton Handlers
error handling utilities
Installation
pip install --upgrade qaviton_handlers
Requirements
- Python 3.6+
Features
- retry decorator ✓
- retry with context ✓
- try functions ✓
- catch errors ✓
- simple Exception wrapper ✓
Usage
retry decorator
from qaviton_handlers.try_decorator import retry
@retry()
def foo():
n = int('1'+input('select number:'))
print(n)
foo()
retry with context
from qaviton_handlers.try_context import retry
with retry() as trying:
while trying:
with trying:
print("Attempt #%d of %d" % (trying.attempt, trying.attempts))
raise
using different try wrapper functions
from qaviton_handlers.try_functions import try_to, try_or_none, multi_try, multi_try_no_break
def foo(a=0):
print(float(a+input("select number:")))
# simply try
try_to(foo, 1)
try_to(foo, 2)
try_to(foo, 3)
# get the error
error = try_to(foo, 4)
if error: print(error)
# if error occurred
if try_to(foo, 5):
try_to(foo, 5)
# try to get a number
number = try_or_none(lambda a:float(a+input("select number:")), 6)
if number: print(number)
# try many functions, return a list of results, or an error
# if an error occurred, the multi try stops
multi_try(
foo,
foo,
foo,
lambda: foo(7),
lambda: foo(7),
lambda: foo(7),
)
# try many functions, return a list of results, some may be errors
# if an error occurred, the multi try continues
multi_try_no_break(
lambda: foo(8),
lambda: foo(9),
lambda: foo(0),
)
ignore errors now so you can handle them later
from qaviton_handlers.catch import Catch
catch = Catch()
try:
1+'1'
except Exception as e:
catch(e)
with catch():
1+'1'
2+'2'
print(f"caught {catch.count} errors")
print(f"caught first {catch.first}")
print(f"caught last {catch.last}")
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
Built Distribution
Close
Hashes for qaviton_handlers-2019.9.28.23.54.30.360247.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 974c1247e3dee9fcc97519faad1933a1002b52dc45138ae72f7dbe626e4a5736 |
|
MD5 | 5f1dd6c115019e834f102843afd79a89 |
|
BLAKE2b-256 | 6a5b43814c330e63501442f3a66051967ff03638cfd66395fe22ed6168640609 |
Close
Hashes for qaviton_handlers-2019.9.28.23.54.30.360247-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a21520de06f232b9b27d12bb4cb5e1c2670e037d22d7e9cb894c84741dcdfdb3 |
|
MD5 | 3406039927a8f8cb4aaa81c5c1465d4d |
|
BLAKE2b-256 | 22a58aa920a9b287efc6fc77a1de74ee7685cb40f7dc33c24b75ee9d7757c4ec |