diff --git a/README.rst b/README.rst index 5d48c1bb9..92fff20c0 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,18 @@ Quick Example session.write_transaction(add_friends, "Arthur", "Merlin") session.read_transaction(print_friends, "Arthur") +Logging +============= +The driver provides a built-in logging. The following example code enables debug logging and prints out logs at stdout: + +.. code-block:: python + + from neo4j.util import watch + import logging + from sys import stdout + + watch("neo4j.bolt", logging.DEBUG, stdout) + Installation ============ diff --git a/neo4j/bolt/connection.py b/neo4j/bolt/connection.py index 93a43964e..bef051054 100644 --- a/neo4j/bolt/connection.py +++ b/neo4j/bolt/connection.py @@ -507,10 +507,16 @@ def close(self): """ Close all connections and empty the pool. This method is thread safe. """ - with self.lock: - self._closed = True - for address in list(self.connections): - self.remove(address) + if self._closed: + return + try: + with self.lock: + if not self._closed: + self._closed = True + for address in list(self.connections): + self.remove(address) + except TypeError as e: + pass def closed(self): """ Return :const:`True` if this pool is closed, :const:`False` diff --git a/neo4j/v1/api.py b/neo4j/v1/api.py index 3ea5278e1..cb6c70490 100644 --- a/neo4j/v1/api.py +++ b/neo4j/v1/api.py @@ -41,6 +41,7 @@ RETRY_DELAY_MULTIPLIER = 2.0 RETRY_DELAY_JITTER_FACTOR = 0.2 + def last_bookmark(b0, b1): """ Return the latest of two bookmarks by looking for the maximum integer value following the last colon in the bookmark string. @@ -141,10 +142,7 @@ class Driver(object): #: Indicator of driver closure. _closed = False - _lock = None - def __init__(self, pool, **config): - self._lock = RLock() self._pool = pool self._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"]) @@ -185,18 +183,14 @@ def close(self): """ Shut down, closing any open connections that were spawned by this Driver. """ - if self._lock is None: - return - with self._lock: - if not self._closed: - self._closed = True - if self._pool is not None: - self._pool.close() - self._pool = None + if not self._closed: + self._closed = True + if self._pool is not None: + self._pool.close() + self._pool = None def closed(self): - with self._lock: - return self._closed + return self._closed class Session(object):