【问题标题】:Py2neo cypher query results in _assert_unfinished. Can someone let me know why?Py2neo 密码查询结果为 _assert_unfinished。有人可以告诉我为什么吗?
【发布时间】:2014-09-22 22:03:51
【问题描述】:

您好,我正在尝试通过调用另一个脚本中的方法来运行此脚本

session = cypher.Session("http://localhost:7474")
tx = session.create_transaction()

def nodepublish(dpid, port, mac, srcip):
        tx.append("MATCH (n:Switch) WHERE n.DPID='"+str(dpid)+"' RETURN n")
        match_switch = tx.execute()
        tx.commit()
        for i in match_switch:
                if(i):
                        print "switch exists"
                else:
                        tx.append("CREATE (s:Switch {DPID: '"+str(dpid)+"'})")
                        tx.execute()
                        print ("switch %s  node published" %(dpid))
                        tx.commit()

它总是以这个错误结束

File "/home/thinker/Desktop/Thesis/ryu/ryu/app/vkryuscripts/node_switch_pub_cypher_test.py", line 11, in nodepublish
    tx.append("MATCH (n:Switch) WHERE n.DPID='"+str(dpid)+"' RETURN n")
  File "/usr/local/lib/python2.7/dist-packages/py2neo/cypher.py", line 194, in append
    self._assert_unfinished()
  File "/usr/local/lib/python2.7/dist-packages/py2neo/cypher.py", line 175, in _assert_unfinished
    raise TransactionFinished()
TransactionFinished

谁能告诉我这里的错误是什么?

谢谢

更新: 我发现了别的东西。 如果我在提交后尝试使用 append,它会返回这个错误。

有人知道为什么吗?

【问题讨论】:

    标签: python neo4j py2neo


    【解决方案1】:

    一旦事务被提交或回滚,它就会被标记为“完成”并且不能被重用。您需要为每个计划的提交创建一个新事务 - 在这种情况下,要么将 commit 移动到函数的末尾,要么为每个循环迭代创建一个新事务。

    【讨论】:

      猜你喜欢
      • 2015-07-09
      • 1970-01-01
      • 2020-12-25
      • 2014-11-25
      • 1970-01-01
      • 2021-11-16
      • 2020-02-21
      • 2020-10-30
      相关资源
      最近更新 更多