@@ -102,7 +102,7 @@ def session(self):
102
102
return session
103
103
104
104
def recycle (self , session ):
105
- """ Pass a session back to the driver for recycling, if healthy.
105
+ """ Accept a session for recycling, if healthy.
106
106
107
107
:param session:
108
108
:return:
@@ -114,9 +114,6 @@ def recycle(self, session):
114
114
if session .healthy and len (pool ) < self .max_pool_size and session not in pool :
115
115
pool .appendleft (session )
116
116
117
- def close (self ):
118
- pass # TODO
119
-
120
117
121
118
class ResultCursor (object ):
122
119
""" A handler for the result of Cypher statement execution.
@@ -138,6 +135,7 @@ def __init__(self, connection, statement, parameters):
138
135
self ._next = deque ()
139
136
self ._position = - 1
140
137
self ._summary = None
138
+ self ._consumed = False
141
139
142
140
def is_open (self ):
143
141
""" Return ``True`` if this cursor is still open, ``False`` otherwise.
@@ -161,7 +159,7 @@ def next(self):
161
159
self ._current = Record (self .keys , tuple (map (hydrated , values )))
162
160
self ._position += 1
163
161
return True
164
- elif self ._summary :
162
+ elif self ._consumed :
165
163
return False
166
164
else :
167
165
self ._connection .fetch_next ()
@@ -183,7 +181,7 @@ def at_end(self):
183
181
"""
184
182
if self ._next :
185
183
return False
186
- elif self ._summary :
184
+ elif self ._consumed :
187
185
return True
188
186
else :
189
187
self ._connection .fetch_next ()
@@ -221,7 +219,7 @@ def summarize(self):
221
219
def _consume (self ):
222
220
# Consume the remainder of this result, triggering all appropriate callback functions.
223
221
fetch_next = self ._connection .fetch_next
224
- while self ._summary is None :
222
+ while not self ._consumed :
225
223
fetch_next ()
226
224
227
225
def _on_header (self , metadata ):
@@ -235,9 +233,11 @@ def _on_record(self, values):
235
233
def _on_footer (self , metadata ):
236
234
# Called on receipt of the result footer.
237
235
self ._summary = ResultSummary (self .statement , self .parameters , ** metadata )
236
+ self ._consumed = True
238
237
239
238
def _on_failure (self , metadata ):
240
239
# Called on execution failure.
240
+ self ._consumed = True
241
241
raise CypherError (metadata )
242
242
243
243
@@ -411,6 +411,7 @@ def __init__(self, driver):
411
411
self .driver = driver
412
412
self .connection = connect (driver .host , driver .port , ** driver .config )
413
413
self .transaction = None
414
+ self .last_cursor = None
414
415
415
416
def __del__ (self ):
416
417
if not self .connection .closed :
@@ -468,11 +469,14 @@ def run(self, statement, parameters=None):
468
469
self .connection .append (PULL_ALL , response = pull_all_response )
469
470
self .connection .send ()
470
471
472
+ self .last_cursor = cursor
471
473
return cursor
472
474
473
475
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.
475
477
"""
478
+ if self .last_cursor :
479
+ self .last_cursor .close ()
476
480
self .driver .recycle (self )
477
481
478
482
def begin_transaction (self ):
0 commit comments