【问题标题】:Neo4j Python 4.4 API using timeoutNeo4j Python 4.4 API 使用超时
【发布时间】:2022-08-19 00:09:13
【问题描述】:

我想在 1 秒后通过启动来中断我的 Neo4j 查询,但它不起作用。

我使用这个 Python 代码:

query = \"text of neo4j query, doesn\'t matter\"
driver = GraphDatabase.driver(uri=\"doesn\'t matter\")
session = driver.session()
result = session.run(Query(query, timeout=1.0), name=\'query\')
d = result.data()

我的长查询无限期地挂起,我不知道如何打破它们。

在 API 文档 4.4 Neo4j Python 库中有很多方法可以做到这一点,但它们都不起作用(可能是我的错误,但我不明白为什么)。

    标签: python api neo4j timeout


    【解决方案1】:

    我发现这个文档解释了在配置文件中设置超时的设置。

    https://neo4j.com/developer/kb/understanding-transaction-and-lock-timeouts/

    在该文档的底部,我尝试使用此 APOC 函数 apoc.cypher.runTimeboxed 并且效果很好。最后一个参数是 1 毫秒,所以它在使用 1 毫秒时不返回数据,而在我输入 100 毫秒时返回数据。

    from neo4j import GraphDatabase
    
    query = """
        CALL apoc.cypher.runTimeboxed("MATCH (n:Person{name:'Keanu Reeves'})-[*]-(other)
        RETURN count(*) as allPathsCount",
        {}, 1)"""
        
    uri="bolt://localhost:7687"
    user="neo4j"
    password="password"
    
    driver = GraphDatabase.driver(uri, auth=(user, password))
    
    session = driver.session()
    
    result = session.run(query)
    d = result.data()
    
    print(d)
    
    
    Using 1ms:  []
    Using 100ms:  [{'value': {'allPathsCount': 12}}]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-04
      • 2020-05-15
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      • 2015-09-02
      相关资源
      最近更新 更多