Skip to content

Commit

Permalink
close session
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchang0812 committed Feb 9, 2017
1 parent 284588e commit 9a99f21
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions qcloud_cos/cos_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import hashlib
import urllib
from contextlib import closing
import cos_auth
from cos_err import CosErr
from cos_request import UploadFileRequest
Expand Down Expand Up @@ -533,15 +534,15 @@ def _upload_slice_data(self, request, file_content, session, offset, retry=3):
def __download_url(self, uri, filename):
session = self._http_session

ret = session.get(uri, stream=True)
if ret.status_code in [200, 206]:
with open(filename, 'wb') as f:
for chunk in ret.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.flush()
else:
raise IOError("download failed " + ret.text)
with closing(session.get(uri, stream=True)) as ret:
if ret.status_code in [200, 206]:
with open(filename, 'wb') as f:
for chunk in ret.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.flush()
else:
raise IOError("download failed " + ret.text)

def download_file(self, request):
assert isinstance(request, DownloadFileRequest)
Expand Down

0 comments on commit 9a99f21

Please sign in to comment.