Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of Class variable storage and move to instance storage #191

Open
corby opened this issue Apr 18, 2017 · 3 comments
Open

Get rid of Class variable storage and move to instance storage #191

corby opened this issue Apr 18, 2017 · 3 comments

Comments

@corby
Copy link

corby commented Apr 18, 2017

I'm building an admin/monitoring server that handles requests from both out production and qa Shopify store.
In the current setup, the user/password/site_uri are stored at the class level, so I can't create a prod session and a qa session and store them in memory.
For every request to the REST server I have to clear the current class variables and set for requested environment.

Additionally, this is not thread safe. If two REST requests arrive at the same time for different endpoints, they will clobber each other.

@metatick
Copy link

+1 for this - very easy to solve this and will prevent unexpected behaviour for apps running under different environments (eg. threads vs processes, persistent vs cgi).

@VichoReyes
Copy link

(maybe this wasn't in place when you raised this issue, I'm not sure)

@corby The sessions are actually in thread-local storage. I don't fully understand how it works (I'm reading about metaclasses now) but the ShopifyResource class somehow uses ShopifyResourceMeta properties, which are based on the _theadlocal object, an instance of threading.local.

I believe this makes them thread-safe.

@odie5533
Copy link

@corby The sessions are actually in thread-local storage.

It also makes it difficult to work on them in an async environment because work is not always done on the same thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants