Flushing results after closing session in Python neo4j-driver

Good evening,
Really enjoying the GraphDB and Neo4j thanks!
I have a question about the use of the Neo4j-driver official Python Driver.
I created a Python script to extract ActiveDirectory objects and Put them in Neo4j GraphDB.
It is working, but I am not sure if I am using the the Driver correctly.
The thing is, when i turn on Logging I see the "session.run" and "Cypher" statements.
When the scripts is at the bottom it executes "session.close", but then it seems like all the "Cypher" statements are run again causing a lot of Disk IO.

Could it be that I'am using the driver the wrong way?

Yours Kindly
Omerule
The Netherlands

PS the script I put on github:

Hi Omerule

I'm not sure exactly what problem you're trying to highlight, since you mention that the code works. In terms of "using the driver correctly" though, there are a few things I'd probably do differently, although nothing there is wrong per se.

Firstly, you might benefit from breaking up your script into functions to make it easier to read. Each function can spawn its own Session object from the driver, since sessions are cheap and disposable -- they borrow connections as required from the connection pool.

Secondly, you are using session.run everywhere, which does a network sync every time it's called. Using transactions instead, with a trailing commit (in particular for your loops) might improve performance by doing fewer round trips to the network and use fewer network packets.

Thirdly, your welder function dynamically creates Cypher query strings. This might be necessary for your domain but bear in mind that wherever you can reuse a Cypher string, albeit with different parameters, you will be able to avoid the Cypher compilation step on the server. Allow the Cypher engine to do substitution wherever possible and don't try to do it yourself.

Nigel

Good afternoon Nigel,
I will take your advice and try to implement them in the script.
Also do my homework by reading:
https://neo4j.com/docs/api/python-driver/1.7-preview/transactions.html

Thank you very much for your advice.

Yours kindly
Omerule