neo4j-contrib / py2neo

EOL! Py2neo is a comprehensive Neo4j driver library and toolkit for Python.
https://py2neo.org
Apache License 2.0
20 stars 8 forks source link

Getting Transaction.TransactionTimedOut when connecting to neo4j sandbox #937

Closed cmosguy closed 2 years ago

cmosguy commented 2 years ago

I am running the following function:

def add_edges(edge_ls):

    edge_dc = {} 

    # Group tuple by verb
    # Result: {verb1: [(sub1, v1, obj1), (sub2, v2, obj2), ...],
    #          verb2: [(sub3, v3, obj3), (sub4, v4, obj4), ...]}

    for tup in edge_ls: 
        if tup[1] in edge_dc: 
            edge_dc[tup[1]].append((tup[0], tup[1], tup[2])) 
        else: 
            edge_dc[tup[1]] = [(tup[0], tup[1], tup[2])] 

    for edge_labels, tup_ls in tqdm(edge_dc.items()):   # k=edge labels, v = list of tuples

        tx = graph.begin()

        for el in tup_ls:
            source_node = nodes_matcher.match(name=el[0]).first()
            target_node = nodes_matcher.match(name=el[2]).first()
            if not source_node:
                source_node = Node('Node', name=el[0])
                tx.create(source_node)
            if not target_node:
                try:
                    target_node = Node('Node', name=el[2], node_labels=el[4], url=el[5], word_vec=el[6])
                    tx.create(target_node)
                except:
                    continue
            try:
                rel = Relationship(source_node, edge_labels, target_node)
            except:
                continue
            tx.create(rel)
        tx.commit()

    return

add_edges(edges_word_vec_ls)

And when I do this I keep getting a Transaction.TransactionTimedOut, how do I set the timeout here?

ClientError: [Transaction.TransactionTimedOut] The transaction has been terminated. Retry your operation in a new transaction, and you should see a successful result. The transaction has not completed within the specified timeout (dbms.transaction.timeout). You may want to retry with a longer timeout. 
motey commented 2 years ago

Hi @cmosguy,

dbms.transaction.timeout is the timeout dictated by the Neo4J database itself. You could change it https://neo4j.com/docs/operations-manual/current/monitoring/transaction-management/ or break down your function into multiple transactions or think about a refactoring otherwise.

i hope this helps