gpt4 book ai didi

python - Py2neo 密码查询结果为 _assert_unfinished。有人可以告诉我为什么吗?

转载 作者:太空宇宙 更新时间:2023-11-04 03:41:56 33 4
gpt4 key购买 nike

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

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

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

谢谢

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

有人知道为什么吗?

最佳答案

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

关于python - Py2neo 密码查询结果为 _assert_unfinished。有人可以告诉我为什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25983807/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com