1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +01:00

simplify no_except_close

This commit is contained in:
Ilya Kreymer 2020-01-22 20:51:40 -08:00
parent 5278d5128b
commit 8c1624a360

View File

@ -6,25 +6,22 @@ from warcio.limitreader import LimitReader
from warcio.utils import BUFF_SIZE from warcio.utils import BUFF_SIZE
# =============================================================================
def no_except_close(closable): def no_except_close(closable):
"""Attempts to call the close method of the """Attempts to call the close method of the
supplied object. supplied object catching all exceptions.
Also tries to call release_conn() in case a requests raw stream
:param closable: The object to be closed :param closable: The object to be closed
:rtype: None :rtype: None
""" """
if not closable:
return
try: try:
closable.close() closable.close()
except Exception: except Exception:
pass pass
try: try:
release_conn = getattr(closable, 'release_conn', None) closable.release_conn()
if release_conn is not None:
release_conn()
except Exception: except Exception:
pass pass