I solved the issue by creating a parallel thread which is scheduled to fire a query every 30s (add and delete a node). This is because, if the connection is idle for more than 2-3 minutes, it will be closed (from my understanding).
Hope that's help.
I had the same problem and basically tried all of the methods mentioned scattered over google, plus some others.
Used Neo4j instead of py2neo, using write_transaction. This didn't work
Set the max_connection_lifetime, keep_alive parameters etc. This didn't work
Setting a parallel thread to periodically create / delete nodes. This didn't work
Created a method that split files into temporary chunks instead of using PERIODIC COMMIT. This didn't work
I had previously noticed in the task manager that memory allocation dropped heavily just before this error appeared - I initially thought that this was a connection issue rather than memory issue... But lo and behold, updating the memory allocations in the Neo4j settings to higher values was the only thing that managed to prevent this error from occurring.