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

Second thread not recorded #295

Closed
delijati opened this issue Feb 7, 2017 · 4 comments
Closed

Second thread not recorded #295

delijati opened this issue Feb 7, 2017 · 4 comments
Labels
stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though!

Comments

@delijati
Copy link

delijati commented Feb 7, 2017

When run with multiple threads THREADS = 2, only the one call is recorded:

import requests
import concurrent.futures
import vcr


THREADS = 2


@vcr.use_cassette('first-only-used.yaml')
def load_urls(urls):
    with concurrent.futures.ThreadPoolExecutor(
            max_workers=THREADS) as executor:
        fs = [executor.submit(requests.get, url) for url in urls]
        for f in concurrent.futures.as_completed(fs):
            try:
                result = f.result()
                print('Result: %s' % result.json())
            except Exception as e:
                print('Error %s' % e)


if __name__ == '__main__':
    urls = [
        'https://httpbin.org/get?q=first',
        'https://httpbin.org/get?q=second'
    ]
    load_urls(urls)

First call:

% env/bin/python thread_vcr.py                                                                                                                                       
Result: {u'origin': u'xx.180.xx.95', u'headers': {u'Host': u'httpbin.org', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.12.1'}, u'args': {u'q': u'second'}, u'url': u'https://httpbin.org/get?q=second'}
Result: {u'origin': u'xx.180.xx.95', u'headers': {u'Host': u'httpbin.org', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.12.1'}, u'args': {u'q': u'first'}, u'url': u'https://httpbin.org/get?q=first'}

Second call:

% env/bin/python thread_vcr.py
Error No match for the request (<Request (GET) https://httpbin.org/get?q=second>) was found. Can't overwrite existing cassette ('first-only-used.yaml') in your current record mode ('once').
Result: {u'origin': u'xx.180.xx.95', u'headers': {u'Host': u'httpbin.org', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.12.1'}, u'args': {u'q': u'first'}, u'url': u'https://httpbin.org/get?q=first'}

Yaml:

% cat first-only-used.yaml 
interactions:
- request:
    body: null
    headers:
      Accept: ['*/*']
      Accept-Encoding: ['gzip, deflate']
      Connection: [keep-alive]
      User-Agent: [python-requests/2.12.1]
    method: GET
    uri: https://httpbin.org/get?q=first
  response:
    body: {string: !!python/unicode "{\n  \"args\": {\n    \"q\": \"first\"\n  },\
        \ \n  \"headers\": {\n    \"Accept\": \"*/*\", \n    \"Accept-Encoding\":\
        \ \"gzip, deflate\", \n    \"Host\": \"httpbin.org\", \n    \"User-Agent\"\
        : \"python-requests/2.12.1\"\n  }, \n  \"origin\": \"xx.180.xx.95\", \n \
        \ \"url\": \"https://httpbin.org/get?q=first\"\n}\n"}
    headers:
      access-control-allow-credentials: ['true']
      access-control-allow-origin: ['*']
      connection: [keep-alive]
      content-length: ['267']
      content-type: [application/json]
      date: ['Tue, 07 Feb 2017 14:29:38 GMT']
      server: [nginx]
    status: {code: 200, message: OK}
version: 1
@delijati
Copy link
Author

delijati commented Feb 7, 2017

If i remove force_reset in vcr/stubs/__init__.py +246 as suggested in #212 then are both requests recorded.

@colonelpanic8
Copy link
Collaborator

See the discussion in #213 . vcrpy is not meant to be thread safe at the momement. It seems that there is a solution

graingert pushed a commit to graingert/vcrpy that referenced this issue Mar 22, 2017
Aaron1011 pushed a commit to Aaron1011/vcrpy that referenced this issue Jul 10, 2017
@neozenith neozenith added the stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though! label Jan 5, 2020
@neozenith
Copy link
Collaborator

A lot of changes have happened to VCRpy since this ticket was opened. As this ticket has become stale and we have a lot of old tickets that need to be groomed, I'm closing this for now to make it easier to see what is still relevant.

However if it is still needed, please feel free to re-open or create a new ticket.

Thanks! 🙏

@salomvary
Copy link

This is still an issue in vcrpy 4.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants