Comments (9)
Hi @teeberg,
Gutter is backed by durabledict
, which should give you a consistent[1] view of switches in your data store, even if there is a copy of the manger per thread. Was there a specific issue or some other problem you were running into that was unexpected with multiple threads.
[1] Obviously the memory backend will not be consistent, but the Redis and ZooKeeper ones should be consistent enough no problem.
from gutter.
Hi @Fluxx, thanks for the fast answer! My understanding of gutter was clearly not good enough to correctly identify the problem. :-) We are in fact using a memory backend in our test environment. When we settled for it, we didn't worry about multiple threads. I also didn't realise this would cause a problem. Thanks for clarifying!
from gutter.
I've debugged some more and tracked down what I think is the real problem: What really doesn't work in the two-thread scenario is the SwitchContextManager
from gutter.client.testutils
. It temporarily overrides gutter.active
, but because the gutter
Manager is thread-local, the other thread doesn't pick up this change. Making the Manager
inherit from object
instead of threading.local
fixes the problem, but that can't be the solution. :-)
from gutter.
Ah yeah. That's a limitation of SwitchContextManager
since, as you mentioned, it monkey patches gutter.active
.
IIRC (as I wrote that code over 3 years ago), the intention with making the Manager
a threading.local
was to prevent people from shooting themselves in the foot by sharing a Manager
instance as a singleton between threads and causing problems. I still agree with that sentiment I think, but I do hear you that your use case of the Django LiveServerTestCase
would be nice to have thread communication on the Manager
state.
I think what might be best in this scenario is to change the class hierarchy a little to have a base somewhat private BaseManager
class not inherit from theading.local
, and instead make the canonical Manager
class inherit from (BaseManager, threading.local)
. Thus for most users they can just use the canonical Manager
class, but for users who need to some more savvy thread coordination they can use a custom manager they inherit from BaseManager
.
Thoughts?
from gutter.
I think it's reasonable to make it thread-local by default. It would of course be nice if the Manager
was fully thread-safe but I'm not sure how hard that would be to achieve.
Leaving that out, what you're suggesting sounds like a quick solution that I could work with! It would be awesome if you could make this change here! Maybe other users can benefit from it too, then :-)
from gutter.
It would be awesome if you could make this change here! Maybe other users can benefit from it too, then :-)
Yeah I can totally do that. Won't be today though, but by the weekend for sure.
from gutter.
Awesome, I'm looking forward to that change! Thank you so much for your efforts!
from gutter.
How do you feel about a patch like this one? teeberg@b887062
from gutter.
That seems like a good idea. I'll be taking a look at this repo soon.
from gutter.
Related Issues (16)
- Chimera is not yet released HOT 1
- Support Python 3 HOT 7
- In The Percentage Range Of works only for integers HOT 2
- Am I doing something wrong? HOT 1
- If this is the client, where is the server? HOT 1
- Persistence api is difficult to understand HOT 6
- Ping HOT 1
- More fine grained control to testutils.switches
- allow for case insensitive matching on conditions HOT 4
- Release up to date client on pypi HOT 4
- Enabling features for specific users HOT 1
- parent:child relation not fully functional when using a durabledict other then memorydict HOT 2
- werkzeug requirement HOT 1
- Gutter roadmap HOT 1
- gutter-django blows up when you double register an attribute on a subclass
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gutter.