Giter Club home page Giter Club logo

Comments (8)

craigcitro avatar craigcitro commented on May 18, 2024

yes, apiclient is tied to httplib2, which isn't threadsafe. if you make separate httplib2.Http instances per thread, you'll hit less trouble.

the right answer here is to switch to something like requests, but that's quite a large change.

from google-api-python-client.

jessepollak avatar jessepollak commented on May 18, 2024

Can you point me in the right direction on doing that? Thanks!

from google-api-python-client.

craigcitro avatar craigcitro commented on May 18, 2024

on the "separate instances per thread", do you control thread creation in flask or does it handle it for you?

on the "switch to requests" front, we need to start with oauth2client. this is an extremely involved set of changes.

from google-api-python-client.

jessepollak avatar jessepollak commented on May 18, 2024

I dug around with switching to requests, but ultimately decided it was just going to be too much for me to handle. Would be great though.

Flask controls thread creation. Any way to just pass in the new httplib2.Http object on execute()?

from google-api-python-client.

craigcitro avatar craigcitro commented on May 18, 2024

yeah, the requests switch is a pretty serious set of changes. i've been hoping to start on it in oauth2client for almost a year now, and it's always "ooh ... that looks serious."

execute() actually already does take an optional http argument; probably the one hitch is that you need to make sure it's authorized.

from google-api-python-client.

jessepollak avatar jessepollak commented on May 18, 2024

Yeah, just tried that it was the problem I ran into. Any way to transfer the authorization from the default http argument to a newly initialized one?

from google-api-python-client.

craigcitro avatar craigcitro commented on May 18, 2024

it's a little convoluted, but you could do

client.something().something().execute(http=client.http.credentials.authorize(http=httplib2.Http()))

however, you might need to create the Http instance as a thread local? in any event, the old http has a handle on the credentials used to authorize it, which you can use here.

here we're moving the problem around a little -- multiple threads trying to refresh the credentials at once may hit trouble -- but it's less problematic than multiple threads sharing the same http connection pool (which is always bad juju).

from google-api-python-client.

jessepollak avatar jessepollak commented on May 18, 2024

That worked, thanks!

from google-api-python-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.