0

I've got a rather large graph in Neo4j and need to do some computational stuff with it. This is why I need to do it on a HPC cluster. So far so good. But my programm accesses the neo4j graph several times which I can not do on the cluster. This is why I wanted to dump the graph object with pickle.dump(). Unfortunately I get an error:

File "...myFile.py", line 9, in pickle.dump(Graph("bolt:///localhost:7474/", auth=("neo4j", "0000")), f) AttributeError: Can't pickle local object 'ConnectionPool.connect..'

My (simplified) code:

import pickle
from py2neo import Graph

graph2 = Graph("bolt:///localhost:7474/", auth=("neo4j", "0000"))

with open('graph.pkl', 'wb') as f:
    pickle.dump(Graph("bolt:///localhost:7474/", auth=("neo4j", "0000")), f)

with open('graph.pkl', 'rb') as f:
    graph = pickle.load(f)

print("Hello")

Can someone tell me, why I get this error (and possibly how to get rid of it)? Thank you very much in advance.

T-Man
  • 47
  • 9

2 Answers2

1

I guess you get this error because you're not just trying to dump the nodes and relationships, but the whole instance of the Graph class, including functions, etc.

It's not clear to me how the dump will help you achieve your goal.
This answer looks promissing though: https://stackoverflow.com/a/31809054/2403344
The idea is to create a Python iGraph from your Neo4j DB. This could then be pickled etc.

Thomas J
  • 146
  • 10
0

What you need to do is to implement __getstate__ and __setstate__. See here for an example. I think you will have to extend Graph in order to implement those methods.

balderman
  • 22,927
  • 7
  • 34
  • 52