try:
some_dangerous_stuff()
except ValueError as e:
...
try:
some_dangerous_stuff()
except ValueError:
fallback()
Traceback (most recent call last):
File "...", line 15, in main
some_dangerous_stuff()
File "...", line 10, in some_dangerous_stuff
return int('a')
ValueError: invalid literal for int() with base 10: 'a'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "...", line 21, in <module>
main()
File "...", line 17, in main
fallback()
File "...", line 2, in fallback
raise RuntimeError('cannot perform action')
RuntimeError: cannot perform action
try:
some_dangerous_stuff()
except ValueError as e:
raise MyError(str(e))
try:
some_dangerous_stuff()
except ValueError as e:
raise MyError(str(e))
Traceback (most recent call last):
File "...", line 15, in main
some_dangerous_stuff()
File "...", line 10, in some_dangerous_stuff
return int('a')
ValueError: invalid literal for int() with base 10: 'a'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "...", line 21, in <module>
main()
File "...", line 17, in main
raise MyError(str(e))
__main__.MyError: invalid literal for int() with base 10: 'a'
try:
some_dangerous_stuff()
except ValueError as e:
raise MyError('description') from e
Traceback (most recent call last):
File "...", line 15, in main
some_dangerous_stuff()
File "...", line 10, in some_dangerous_stuff
return int('a')
ValueError: invalid literal for int() with base 10: 'a'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "...", line 21, in <module>
main()
File "...", line 17, in main
raise MyError('description') from e
__main__.MyError: description
def main():
try:
raise MyError('test')
except MyError as e:
print(f'context: {e.__context__}')
print(f'cause: {e.__cause__}')
context: None
cause: None
def func1():
return int('a')
def func2():
try:
func1()
except ValueError:
raise MyError('description')
def main():
try:
func2()
except MyError as e:
print(f'context: {e.__context__}')
print(f'cause: {e.__cause__}')
context: invalid literal for int() with base 10: 'a'
cause: None
def func1():
return int('a')
def func2():
try:
func1()
except ValueError as ve:
raise MyError('description') from ve
def main():
try:
func2()
except MyError as e:
print(f'context: {e.__context__}')
print(f'cause: {e.__cause__}')
context: invalid literal for int() with base 10: 'a'
cause: invalid literal for int() with base 10: 'a'
try:
func1()
except ValueError as ve:
e = MyError('description')
e.__cause__ = ve
raise e
try:
func1()
except ValueError as ve:
raise MyError('description') from e
error = None
try:
func1()
except ValueError as ve:
error = ve
if error:
e = MyError('description')
raise e from error
try:
some_dangerous_stuff()
except ValueError as e:
some_lock.release()
raise
try:
some_dangerous_stuff()
finally:
some_lock.release()
def _get_dump():
xs = []
for obj in gc.get_objects():
...
referents = gc.get_referents(obj)
...
return xs
def dump_gc_mem(signum, frame):
dump = _get_dump()
with pathlib.Path('mem.pickle').open('wb') as f:
pickle.dump(dump, f)
signal.signal(signal.SIGUSR1, dump_gc_mem)
@lru_cache(maxsize=1000)
def fetch(
self,
data: Request,
headers: RequestHeaders
) -> RecognizeResponse:
...
# arenas allocated total = 373
# arenas reclaimed = 0
# arenas allocated current = 373
373 arenas * 262144 bytes/arena = 97,779,712
def _graph(self) -> AGraph:
return self._get_state_machine()
def _graph(self) -> AGraph:
return self._get_state_machine(use_pygraphviz=False)