GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.04k stars 230 forks source link

issue with instance context within the synchronized decorator #145

Closed daniel-o-jones closed 4 years ago

daniel-o-jones commented 4 years ago

I've run into an issue using wrapt's synchronized decorator

Previous behaviour and comment in the _synchronized_wrapper function implies the instance has to be None before wrapped is used as the context in the _synchronized_lock function. But the way it's working now means that a Falsey (but not None) instance isn't getting used as the context

Changing line 499 to with _synchronized_lock(instance if instance is not None else wrapped): is a one line solution of the problem that works for our use case

GrahamDumpleton commented 4 years ago

Yep. Am curious though as to what type of object you were applying it to that you hit that. An instance of some custom type of your own, or something from a third party library?

GrahamDumpleton commented 4 years ago

Add test and change notes in https://github.com/GrahamDumpleton/wrapt/commit/0c98567e78837bb39b2a498c13a0eb1403266bee

GrahamDumpleton commented 4 years ago

Note that I will probably only release a new version in a week or so. Am about to be travelling for a bit and don't want to do it right now as internet access the next week may be unpredictable.

daniel-o-jones commented 4 years ago

We were using an internal object that is a cache. When it's empty it is falsey. Looking forward to the update!