betamaxpy / betamax

A VCR imitation designed only for python-requests.
https://betamax.readthedocs.io/en/latest/
Other
567 stars 62 forks source link

Make cassettes thread-safe #52

Open sigmavirus24 opened 9 years ago

sigmavirus24 commented 9 years ago

I'm wondering if there's a need to test items using requests in thread-safe manner and how that would work with betamax. Currently the access to cassette files is not threadsafe and I'm wondering what would be necessary to ensure thread-safety.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9271963-make-cassettes-thread-safe?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github).
sigmavirus24 commented 9 years ago

So, we'd probably have to use pylockfile to ensure we don't update the same cassette twice. That would probably give us 90% of what we need. Namely, this would be great for the case where we are testing an application that's sharing a session between threads. Even though this isn't a recommendation requests makes, Betamax should still attempt to support it.

Further, I think the dependency on pylockfile should be optional that could be installed from an extra for betamax, e.g., pip install betamax[threadsafe].

The code to integrate this with the current Cassette class should be minimal.