Skip to content

Commit

Permalink
Fix BrokenPipeError
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkovtsev committed Aug 17, 2016
1 parent 09aa60c commit d0b9cca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions jgscm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ def _get_bucket(self, name, throw=False):
except KeyError:
try:
bucket = self.client.get_bucket(name)
except BrokenPipeError:
return self._get_bucket(name, throw)
except (BadRequest, NotFound):
if throw:
raise
Expand Down Expand Up @@ -520,8 +522,11 @@ def _fetch(self, path, content=True):
tuple(file [Blob], folders list)).
"""
if path == "":
buckets = self.client.list_buckets()
return True, ([], [b.name + "/" for b in buckets])
try:
buckets = self.client.list_buckets()
return True, ([], [b.name + "/" for b in buckets])
except BrokenPipeError:
return self._fetch(path, content)
try:
bucket_name, bucket_path = self._parse_path(path)
except ValueError:
Expand All @@ -536,15 +541,21 @@ def _fetch(self, path, content=True):
return True, None
if bucket_path == "" or bucket_path.endswith("/"):
if bucket_path != "":
exists = bucket.blob(bucket_path).exists()
try:
exists = bucket.blob(bucket_path).exists()
except BrokenPipeError:
return self._fetch(path, content)
if exists and not content:
return True, None
# blob may not exist but at the same time be a part of a path
max_list_size = self.max_list_size if content else 1
try:
it = bucket.list_blobs(prefix=bucket_path, delimiter="/",
max_results=max_list_size)
files = list(it)
try:
files = list(it)
except BrokenPipeError:
return self._fetch(path, content)
except NotFound:
del self._bucket_cache[bucket_name]
return False, None
Expand All @@ -553,7 +564,10 @@ def _fetch(self, path, content=True):
(files, folders) if content else None)
if not content:
return bucket.blob(bucket_path).exists, None
blob = bucket.get_blob(bucket_path)
try:
blob = bucket.get_blob(bucket_path)
except BrokenPipeError:
return self._fetch(path, content)
return blob is not None, blob

def _base_model(self, blob):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name="jgscm",
description="Jupyter Google Cloud Storage ContentsManager",
version="0.1.2",
version="0.1.4",
license="MIT",
author="Vadim Markovtsev",
author_email="vadim@sourced.tech",
Expand Down

0 comments on commit d0b9cca

Please sign in to comment.