question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Cloud Storage failing when using threads

See original GitHub issue
  1. Ubuntu 16.04
  2. Python 2.7.6
  3. google-api-python-client>=1.6.2 and google-cloud-storage>=1.1.1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
    raise self._value
ssl.SSLError: [Errno 1] _ssl.c:1429: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
  1. The client is not thread safe (I think)
from multiprocessing.pool import ThreadPool
from google.cloud import storage
from functools import partial

def upload(bucket, i):
    blob = bucket.blob("file{}.png".format(i))
    blob.upload_from_string("blabla")
    blob.make_public()
    return blob.public_url

bucket = storage.Client().get_bucket("deepo-test")
pool = ThreadPool()
fct = partial(upload, bucket)
pool.map(fct, [i for i in range(2)])

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
kumudrajcommented, Aug 12, 2019

you need to create a new client connection for every pool / thread inside def upload(bucket, i). That will be work.

from multiprocessing.pool import ThreadPool from google.cloud import storage

def upload(i): bucket = storage.Client().get_bucket(“deepo-test”) blob = bucket.blob(“file{}.png”.format(i)) blob.upload_from_string(“blabla”) blob.make_public() return blob.public_url

pool = ThreadPool() pool.map(fct, [i for i in range(2)])

3reactions
dhermescommented, Jun 14, 2017

@Alexis-Jacob That’s correct, the error you are seeing is caused by the lack of thread-safety in httplib2. We recommend (for now) creating an instance of Client that is local to your thread / process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Dataflow errors - Google Cloud
If you run into problems with your Dataflow pipeline or job, this page lists error messages that you might see and provides suggestions...
Read more >
gsutil failing on worker_thread.start() - Stack Overflow
I have been using gsutil for the past 3 months. I noticed an error that occurs randomly from time to time, e.g. sometimes...
Read more >
Backup failing for Google Cloud Storage - Duplicacy Forum
The -threads option only sets the number of uploading threads. There is only one chunking thread that splits files into chunks and then ......
Read more >
Bottleneck while uploading lots of files to GCP bucket in a ...
google.cloud.storage.StorageException: Connect timed out,” exception when I exceed 25 threads. Going beyond 60 threads, the programs don' ...
Read more >
Storageclient.ListObjects causes thread cancel error when ...
I have some code that fetches files from Google Cloud Storage. ... LogToConsole($" - Failed to download attachment with name {fileName}"); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found