Skip to content

got incorrect result with gevent  #52

Description

@torpedoallen
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.

Activity

  1. jaysonsantos commented on Jul 12, 2016

    @jaysonsantos
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions