From 572e561540ca810f5927f174c68261fe43ae25eb Mon Sep 17 00:00:00 2001 From: Neil Grey Date: Mon, 25 Apr 2016 12:13:01 -0700 Subject: [PATCH 1/2] For #36143: Explicitly closing download_attachment file handler --- shotgun_api3/shotgun.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index e3d1b8a5..1c7497b1 100755 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -1586,6 +1586,7 @@ def download_attachment(self, attachment=False, file_path=None, req = urllib2.urlopen(request) if file_path: shutil.copyfileobj(req, fp) + fp.close() else: attachment = req.read() # 400 [sg] Attachment id doesn't exist or is a local file @@ -1612,6 +1613,8 @@ def download_attachment(self, attachment=False, file_path=None, raise ShotgunFileDownloadError(err) else: if file_path: + if not fp.closed: + fp.close() return file_path else: return attachment From 55da503f51039043ffdef24570bd33473eb19d98 Mon Sep 17 00:00:00 2001 From: Neil Grey Date: Mon, 25 Apr 2016 12:22:42 -0700 Subject: [PATCH 2/2] For #36143: Dropping close in try clause, as it's redundant with else clause calling it later --- shotgun_api3/shotgun.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 1c7497b1..33c048ad 100755 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -1586,7 +1586,6 @@ def download_attachment(self, attachment=False, file_path=None, req = urllib2.urlopen(request) if file_path: shutil.copyfileobj(req, fp) - fp.close() else: attachment = req.read() # 400 [sg] Attachment id doesn't exist or is a local file