Question

I am passing a dictionary of the form

{'twitterid':121212, 'followers':[121,212323,2323,1221]}

to the function createVertex

def createVertex(userDict):
    vertex = g.vertices.create(twitterid=userDict['twitterid'])
    g.vertices.update(vertex.eid, userDict)

    while not 'followers' in list(vertex.data().iterkeys()):
        print "trying " + str(vertex.twitterid)

    return vertex

It gets stuck in while loop. I suspect there is a "commit" issue in update or a race issue. Can someone advise how to fix this problem?

Thanks

Était-ce utile?

La solution

No race condition. vertex doesn't contain userDict in the example you provided because update() doesn't modify it. Use save() instead:

def createVertex(userDict):
    vertex = g.vertices.create(twitterid=userDict['twitterid'])

    vertex.followers = userDict['followers']
    vertex.save()

    return vertex

See https://github.com/espeed/bulbs/blob/master/bulbs/element.py#L505

However, you can do all of the above in one step:

vertex = g.vertices.create(userDict)

See https://github.com/espeed/bulbs/blob/master/bulbs/element.py#L551

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top