2

Hi I am trying to run this script by calling the method from another script

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()

and it always ends up with this error

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

can someone please tell me what the error is here?

Thanks

Update: I found something else. If i try to use append after commit, it is returning me this error.

Anybody know why?

Kiran Vemuri
  • 2,762
  • 2
  • 24
  • 40

1 Answers1

2

Once a transaction has been committed or rolled back, it is marked as 'finished' and cannot be reused. You will need to create a new transaction for each planned commit - in this case, either move the commit to the end of the function or create a new transaction for each loop iteration.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15