-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
minor optimistaion #288
minor optimistaion #288
Conversation
Current coverage is 91.76% (diff: 50.00%)@@ master #288 diff @@
==========================================
Files 7 7
Lines 535 534 -1
Methods 0 0
Messages 0 0
Branches 97 97
==========================================
- Hits 491 490 -1
Misses 43 43
Partials 1 1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing peculiar.
Hey Casper,
To avoid racing conditions, we need an atomic operation, so either a lock or a single opcode. So this would work:
But then this is less elegant (and maybe less efficient?) since we use two different assignments (I believe Python has some optimizations when we do multiple assignments at once). So this should work, but I think that having an additional |
Interesting point. Assignment is a language intrinsic, but a few of my tests shows that self.start_t = self.last_print_t = self._time() should be self.last_print_t = self.start_t = self._time() in order to ensure """
>>> a=Foo('a')
>>> b=Foo('b')
>>> c=Foo('c')
>>> a.A = b.B = 1
setting A 1 in a
setting B 1 in b
"""
class Foo:
def __init__(self, name):
self.__dict__["name"] = name
def __setattr__(self, k, v):
print "setting", k, v, "in", self.name let me know if you get different behaviour. It would be nice to avoid a "started" variable until we actually need it in another PR |
I get the same but we should not rely on this, because the implementation of multiple assignments order might change depending on the platform, the python interpreter (CPython version but also PyPy, Cython, Jython, etc.), because multiple assignments is not meant to be concurrency safe. So I'm ok to remove started, but then just to be on the safe side let's set
|
8cade97
to
a65e347
Compare
No Casper, I disagree with this PR, you can't just merge your own PR whenever you want like this. Are we dropping the review system? Anyway I will remove this merge, it should be:
|
Signed-off-by: Stephen L. <lrq3000@gmail.com>
oh hi @lrq3000 didn't see your message here from 2 days ago. happy with the correction, thanks. |
alternative to 2d45eca
let me know if this doesn't work @lrq3000