Skip to content

Commit d0b9cca

Browse files
committed
Fix BrokenPipeError
1 parent 09aa60c commit d0b9cca

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

jgscm/__init__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ def _get_bucket(self, name, throw=False):
452452
except KeyError:
453453
try:
454454
bucket = self.client.get_bucket(name)
455+
except BrokenPipeError:
456+
return self._get_bucket(name, throw)
455457
except (BadRequest, NotFound):
456458
if throw:
457459
raise
@@ -520,8 +522,11 @@ def _fetch(self, path, content=True):
520522
tuple(file [Blob], folders list)).
521523
"""
522524
if path == "":
523-
buckets = self.client.list_buckets()
524-
return True, ([], [b.name + "/" for b in buckets])
525+
try:
526+
buckets = self.client.list_buckets()
527+
return True, ([], [b.name + "/" for b in buckets])
528+
except BrokenPipeError:
529+
return self._fetch(path, content)
525530
try:
526531
bucket_name, bucket_path = self._parse_path(path)
527532
except ValueError:
@@ -536,15 +541,21 @@ def _fetch(self, path, content=True):
536541
return True, None
537542
if bucket_path == "" or bucket_path.endswith("/"):
538543
if bucket_path != "":
539-
exists = bucket.blob(bucket_path).exists()
544+
try:
545+
exists = bucket.blob(bucket_path).exists()
546+
except BrokenPipeError:
547+
return self._fetch(path, content)
540548
if exists and not content:
541549
return True, None
542550
# blob may not exist but at the same time be a part of a path
543551
max_list_size = self.max_list_size if content else 1
544552
try:
545553
it = bucket.list_blobs(prefix=bucket_path, delimiter="/",
546554
max_results=max_list_size)
547-
files = list(it)
555+
try:
556+
files = list(it)
557+
except BrokenPipeError:
558+
return self._fetch(path, content)
548559
except NotFound:
549560
del self._bucket_cache[bucket_name]
550561
return False, None
@@ -553,7 +564,10 @@ def _fetch(self, path, content=True):
553564
(files, folders) if content else None)
554565
if not content:
555566
return bucket.blob(bucket_path).exists, None
556-
blob = bucket.get_blob(bucket_path)
567+
try:
568+
blob = bucket.get_blob(bucket_path)
569+
except BrokenPipeError:
570+
return self._fetch(path, content)
557571
return blob is not None, blob
558572

559573
def _base_model(self, blob):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
setup(
55
name="jgscm",
66
description="Jupyter Google Cloud Storage ContentsManager",
7-
version="0.1.2",
7+
version="0.1.4",
88
license="MIT",
99
author="Vadim Markovtsev",
1010
author_email="[email protected]",

0 commit comments

Comments
 (0)