-
Notifications
You must be signed in to change notification settings - Fork 154
/
handlers.py
47 lines (32 loc) · 1.25 KB
/
handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# Copyright (c) 2017-2021 NVIDIA CORPORATION. All rights reserved.
# This file is part of the WebDataset library.
# See the LICENSE file for licensing terms (BSD-style).
#
"""Pluggable exception handlers.
These are functions that take an exception as an argument and then return...
- the exception (in order to re-raise it)
- True (in order to continue and ignore the exception)
- False (in order to ignore the exception and stop processing)
They are used as handler= arguments in much of the library.
"""
import time, warnings
def reraise_exception(exn):
"""Call in an exception handler to re-raise the exception."""
raise exn
def ignore_and_continue(exn):
"""Call in an exception handler to ignore any exception and continue."""
return True
def warn_and_continue(exn):
"""Call in an exception handler to ignore any exception, isssue a warning, and continue."""
warnings.warn(repr(exn))
time.sleep(0.5)
return True
def ignore_and_stop(exn):
"""Call in an exception handler to ignore any exception and stop further processing."""
return False
def warn_and_stop(exn):
"""Call in an exception handler to ignore any exception and stop further processing."""
warnings.warn(repr(exn))
time.sleep(0.5)
return False