简体   繁体   中英

How I can close the connection in py2neo?

Just I want to know how to close the connection in py2neo.

graph = py2neo.Graph(password = 'xxxxx',host = 'xxxx')

I try to use

graph.close()

But I receive the next msg.

AttributeError: 'Graph' object has no attribute 'close'

Lib version : py2neo==3.1.2

Regards.

There is no close method. I was wondering the same thing, and having seen no other answer, I started using netstat and tcpdump to watch the behavior of neo4j when connecting via p2neo.

Here's what I learned...

(1) It seems that neo4j (when connecting via HTTP) makes requests very restfully (no persistent connection as with other databases--eg postgres). This means there is actually no need for a .close() method.

(2) The down-side is that you may end up building a list of connections in TIME_WAIT status. This is because no 'Connection':'Close' header is sent. Under low load, this should not be a problem. However, at scale, this will need some tuning at the operating system level (I'll forgo how Java programmers seem to be notorious about not cleaning up after themselves and leaving this to someone else to do. I rant about this too much on too many applications).

Hopefully this helps. Happy Hacking!

To just free up the object, I used:

del graph

so far, no issues. This was because I didn't want a graph and OGM repo connection at the same time...which doesn't appear to be an issue anyways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM