contentful / the-example-app.py

Example app for Contentful in Python
https://www.contentful.com/
MIT License
17 stars 30 forks source link

is services.contenful.instance() reentrant #37

Open chelorossi opened 5 years ago

chelorossi commented 5 years ago

Hi and thanks for your kindness, one question:

Can use it in a flask application dispatching all my routes always calling the same contentful.instance()? To fetch entries in multiple flask routes at same time. I mean without running in any race conditions or locks?,

My use case will be only consuming content

thank you very much for you assistance. Kind Regards

dlitvakb commented 5 years ago

Hey @cheluskis,

It should be thread safe, that said, I'd recommend using the SDK directly, instead of with the service layer on top that is built in this app. This app was built this way, because we needed to have the option to on-the-fly switch between Delivery and Preview APIs. If that's what you need, then this is a good approach. If not, I'd rather avoid the extra complexity and use the SDK directly, which makes it far more simpler.

Cheers

chelorossi commented 5 years ago

Thanks @dlitvakb for the fast response,

Yes I'll be doing something like:

import contentful client = contentful.Client(space_id, client_id)

and use the same client for all routes. That's cause we detected instantiating Client (connection) in every request is expensive.

that's what you meant, right?.

Thanks a lot!