question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

force_reset makes vcr non thread-safe

See original GitHub issue

I tried to use vcr to write tests for an old program that uses threadpools internally. It turned out that this doesn’t work and I believe it’s due to the use of force_reset when the unpatched base classes are instantiated. The reset is necessary since httplib.HTTPSConnection refers to httplib.HTTPConnection by name.

The following program shows unexpected errors on my machine:

import sys, urllib2

from concurrent import futures
from vcr import use_cassette
from vcr.errors import CannotOverwriteExistingCassetteException

@use_cassette('not-actually-used.yaml', record_mode='none')
def load_all(*urls):
    print 'Submitting URLs...',
    with futures.ThreadPoolExecutor(max_workers=2) as executor:
        fs = [executor.submit(urllib2.urlopen, url) for url in urls]
        print 'done!'
        for f in futures.as_completed(fs):
            try:
                result = f.result()
                print 'Unexpected result:', result
                sys.exit(1)
            except CannotOverwriteExistingCassetteException as e:
                pass  # Success!
            except Exception as e:
                print 'Unexpected error:', e
                sys.exit(1)


if __name__ == '__main__':
    load_all('https://httpbin.org/get?q=testing+vcrpy+with',
             'https://httpbin.org/get?q=https+and+threads')

The error shown is

unbound method __init__() must be called with VCRHTTPConnectionnot-actually-used.yaml
instance as first argument (got HTTPSConnection instance instead)

and is triggered when the unpatched httplib.HTTPSConnection.__init__ calls the patched httplib.HTTPConnection.__init__.

I see the error about 50% of the time, so I normally run the script in a little loop (Zsh syntax):

errors=0; for i in {1..20}; do python test.py; ((errors += $?)); echo; echo "*** Successes: $((i - errors))/$i, $((100 * (i - errors) / i))%"; done

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanMalisoncommented, Jul 13, 2021

It is still relevant. Reproducing on vcrpy==4.1.1. @neozenith, can you pls reopen the issue?

@selevit I’m not really that involved in the maintenance of vcrpy anymore, but this is the one area of code I would say I am probably still the resident expert in, and I really don’t think that vcrpy is EVER going to be multi threaded (at least with its current design).

You’re not really reproducing anything, because vcrpy DOES NOT SUPPORT multi threading. The only way it would be able to do so would basically be to put a global lock around everything, at which point you have to ask what the point of multi-threading is in the first place.

0reactions
selevitcommented, Jul 12, 2021

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! 🙏

It is still relevant. Reproducing on vcrpy==4.1.1. @neozenith, can you pls reopen the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - What is non-thread-safety for? - Stack Overflow
Writing thread-safe code: Requires more skilled developers; Is harder and consumes more coding efforts; Is harder to test and debug ...
Read more >
Car Wash Pattern: Parallelizing Non-Thread Safe and/or CPU ...
This will provide us with an environment that will allow CPU-bound and/or non-thread-safe processes to work in controlled parallelism later on.
Read more >
here - GitHub
... 2020-07-01 Fix OTB icon which is not render into QGIS Processing Merge: ... 2020-06-05 make QgsLocalizedPathRegistry thread safe (#36865) Denis Rouzaud ...
Read more >
Untitled
Banana chips making project report, Eiles gimtadienio proga, Penmorfa mine, ... Iphone 6s force reset, Penyengat tanjungpinang, Accumulazione originaria del ...
Read more >
Untitled
Who made the egyptian sphinx, Slackdaddy world hardest game 2? ... Bogenshop tirol, Roshan khayal meaning in english, Dictionary not thread safe c#, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found