python
  • neo4j
  • py2neo
  • 2014-09-22 146 views 1 likes 
    1

    嗨,我想从另一个脚本。有人能告诉我为什么吗?

    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,它将返回此错误。

    有人知道为什么吗?

    回答

    1

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

    相关问题