Skip to content

Commit 331eb6f

Browse files
authored
Merge pull request #188 from zhenlineo/1.5-prevent-close-multiple-times
Prevent pool from closing multiple times
2 parents 37efb65 + 7ba85a9 commit 331eb6f

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ Quick Example
3030
session.write_transaction(add_friends, "Arthur", "Merlin")
3131
session.read_transaction(print_friends, "Arthur")
3232
33+
Logging
34+
=============
35+
The driver provides a built-in logging. The following example code enables debug logging and prints out logs at stdout:
36+
37+
.. code-block:: python
38+
39+
from neo4j.util import watch
40+
import logging
41+
from sys import stdout
42+
43+
watch("neo4j.bolt", logging.DEBUG, stdout)
44+
3345
3446
Installation
3547
============

neo4j/bolt/connection.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,16 @@ def close(self):
507507
""" Close all connections and empty the pool.
508508
This method is thread safe.
509509
"""
510-
with self.lock:
511-
self._closed = True
512-
for address in list(self.connections):
513-
self.remove(address)
510+
if self._closed:
511+
return
512+
try:
513+
with self.lock:
514+
if not self._closed:
515+
self._closed = True
516+
for address in list(self.connections):
517+
self.remove(address)
518+
except TypeError as e:
519+
pass
514520

515521
def closed(self):
516522
""" Return :const:`True` if this pool is closed, :const:`False`

neo4j/v1/api.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
RETRY_DELAY_MULTIPLIER = 2.0
4242
RETRY_DELAY_JITTER_FACTOR = 0.2
4343

44+
4445
def last_bookmark(b0, b1):
4546
""" Return the latest of two bookmarks by looking for the maximum
4647
integer value following the last colon in the bookmark string.
@@ -141,10 +142,7 @@ class Driver(object):
141142
#: Indicator of driver closure.
142143
_closed = False
143144

144-
_lock = None
145-
146145
def __init__(self, pool, **config):
147-
self._lock = RLock()
148146
self._pool = pool
149147
self._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"])
150148

@@ -185,18 +183,14 @@ def close(self):
185183
""" Shut down, closing any open connections that were spawned by
186184
this Driver.
187185
"""
188-
if self._lock is None:
189-
return
190-
with self._lock:
191-
if not self._closed:
192-
self._closed = True
193-
if self._pool is not None:
194-
self._pool.close()
195-
self._pool = None
186+
if not self._closed:
187+
self._closed = True
188+
if self._pool is not None:
189+
self._pool.close()
190+
self._pool = None
196191

197192
def closed(self):
198-
with self._lock:
199-
return self._closed
193+
return self._closed
200194

201195

202196
class Session(object):

0 commit comments

Comments
 (0)