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

got incorrect result with gevent #52

Open
torpedoallen opened this issue Jul 7, 2016 · 1 comment
Open

got incorrect result with gevent #52

torpedoallen opened this issue Jul 7, 2016 · 1 comment

Comments

@torpedoallen
Copy link

import time
import gevent.monkey
gevent.monkey.patch_all()

a = time.time()
mc.set('a', 1)

def add(key):
    #with lock:
    mc.incr(key)

jobs = []
for i in xrange(1000):
    jobs.append(gevent.spawn(add, 'a'))
gevent.joinall(jobs)
print mc.get('a')
mc.delete('a')
print time.time() - a

just like the code above, It gives 995 but 1001 as suppose to be. Is there any idea about this issue?

Thanks in advance.

@jaysonsantos
Copy link
Owner

Hey @torpedoallen I guess it is because it is because you are having a race condition, imagine you have 10 threads trying to increment on the same value (and if there is no value, it will start as 0 I think), it is not predicable which will be the outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants