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

OAuth2Session token not preserved when copied to multiple processes #111

Closed
ruscur opened this issue Mar 14, 2014 · 2 comments
Closed

OAuth2Session token not preserved when copied to multiple processes #111

ruscur opened this issue Mar 14, 2014 · 2 comments

Comments

@ruscur
Copy link

ruscur commented Mar 14, 2014

This is a pretty confusing behaviour, so it's quite possible that this isn't a bug at all, but I figured I'd share it anyway.

The behaviour is as follows:

  1. An OAuth2Session is created, fetch_token is called, and protected resources can be accessed.
  2. Multiple processes (using multiprocessing.Pool) are created to execute a function with this OAuth2Session as a parameter.
  3. The token attribute of this OAuth2Session no longer exists within the memory of these new processes.

It's not a big deal because it just requires each process to fetch the token of their OAuth2Session, but it seems like it should "just work".

@Lukasa
Copy link
Member

Lukasa commented Mar 14, 2014

The general rule in Requests is that Session objects should not be shared across threads. They have access to some state that requires synchronisation and they don't synchronise on it.

@ib-lundgren
Copy link
Member

A side note. The fetch_token method returns a dict which you should be ok sharing over the processes

>>> token = fetch_token(.....)
{ "token": "abc...", "token_type": "Bearer", ....}

>>> # Inside the new process
>>> session = OAuth2Session("client_id", token=token)

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

No branches or pull requests

3 participants