@@ -102,7 +102,7 @@ def session(self):
102102 return session
103103
104104 def recycle (self , session ):
105- """ Pass a session back to the driver for recycling, if healthy.
105+ """ Accept a session for recycling, if healthy.
106106
107107 :param session:
108108 :return:
@@ -114,9 +114,6 @@ def recycle(self, session):
114114 if session .healthy and len (pool ) < self .max_pool_size and session not in pool :
115115 pool .appendleft (session )
116116
117- def close (self ):
118- pass # TODO
119-
120117
121118class ResultCursor (object ):
122119 """ A handler for the result of Cypher statement execution.
@@ -138,6 +135,7 @@ def __init__(self, connection, statement, parameters):
138135 self ._next = deque ()
139136 self ._position = - 1
140137 self ._summary = None
138+ self ._consumed = False
141139
142140 def is_open (self ):
143141 """ Return ``True`` if this cursor is still open, ``False`` otherwise.
@@ -161,7 +159,7 @@ def next(self):
161159 self ._current = Record (self .keys , tuple (map (hydrated , values )))
162160 self ._position += 1
163161 return True
164- elif self ._summary :
162+ elif self ._consumed :
165163 return False
166164 else :
167165 self ._connection .fetch_next ()
@@ -183,7 +181,7 @@ def at_end(self):
183181 """
184182 if self ._next :
185183 return False
186- elif self ._summary :
184+ elif self ._consumed :
187185 return True
188186 else :
189187 self ._connection .fetch_next ()
@@ -221,7 +219,7 @@ def summarize(self):
221219 def _consume (self ):
222220 # Consume the remainder of this result, triggering all appropriate callback functions.
223221 fetch_next = self ._connection .fetch_next
224- while self ._summary is None :
222+ while not self ._consumed :
225223 fetch_next ()
226224
227225 def _on_header (self , metadata ):
@@ -235,9 +233,11 @@ def _on_record(self, values):
235233 def _on_footer (self , metadata ):
236234 # Called on receipt of the result footer.
237235 self ._summary = ResultSummary (self .statement , self .parameters , ** metadata )
236+ self ._consumed = True
238237
239238 def _on_failure (self , metadata ):
240239 # Called on execution failure.
240+ self ._consumed = True
241241 raise CypherError (metadata )
242242
243243
@@ -411,6 +411,7 @@ def __init__(self, driver):
411411 self .driver = driver
412412 self .connection = connect (driver .host , driver .port , ** driver .config )
413413 self .transaction = None
414+ self .last_cursor = None
414415
415416 def __del__ (self ):
416417 if not self .connection .closed :
@@ -468,11 +469,14 @@ def run(self, statement, parameters=None):
468469 self .connection .append (PULL_ALL , response = pull_all_response )
469470 self .connection .send ()
470471
472+ self .last_cursor = cursor
471473 return cursor
472474
473475 def close (self ):
474- """ If still usable, return this session to the driver pool it came from.
476+ """ Recycle this session through the driver it came from.
475477 """
478+ if self .last_cursor :
479+ self .last_cursor .close ()
476480 self .driver .recycle (self )
477481
478482 def begin_transaction (self ):
0 commit comments