def close(self, noreply_wait=False, token=None, exception=None): self._closing = True if exception is not None: err_message = "Connection is closed (%s)." % str(exception) else: err_message = "Connection is closed." # Cursors may remove themselves when errored, so copy a list of them for cursor in list(self._cursor_cache.values()): cursor._error(err_message) for query, future in iter(self._user_queries.values()): if not future.done(): future.set_exception(ReqlDriverError(err_message)) self._user_queries = {} self._cursor_cache = {} if noreply_wait: noreply = Query(pQuery.NOREPLY_WAIT, token, None, None) yield from self.run_query(noreply, False) self._streamwriter.close() # We must not wait for the _reader_task if we got an exception, because that # means that we were called from it. Waiting would lead to a deadlock. if self._reader_task and exception is None: yield from self._reader_task return None
def close(self, noreply_wait=False, token=None, exception=None): d = defer.succeed(None) self._closing = True error_message = "Connection is closed" if exception is not None: error_message = "Connection is closed (reason: {exc})".format( exc=str(exception)) for cursor in list(self._cursor_cache.values()): cursor._error(error_message) for query, deferred in iter(self._user_queries.values()): if not deferred.called: deferred.errback(fail=ReqlDriverError(error_message)) self._user_queries = {} self._cursor_cache = {} if noreply_wait: noreply = Query(pQuery.NOREPLY_WAIT, token, None, None) d = self.run_query(noreply, False) def closeConnection(res): self._connection.transport.loseConnection() return res return d.addBoth(closeConnection)
def close(self, noreply_wait=False, token=None, exception=None): self._closing = True if exception is not None: err_message = "Connection is closed (%s)." % str(exception) else: err_message = "Connection is closed." # Cursors may remove themselves when errored, so copy a list of them for cursor in list(self._cursor_cache.values()): cursor._error(err_message) for query, future in iter(self._user_queries.values()): future.set_exception(ReqlDriverError(err_message)) self._user_queries = {} self._cursor_cache = {} if noreply_wait: noreply = Query(pQuery.NOREPLY_WAIT, token, None, None) yield self.run_query(noreply, False) try: self._stream.close() except iostream.StreamClosedError: pass raise gen.Return(None)
async def close(self, noreply_wait=False, token=None, exception=None): self._closing = True if exception is not None: err_message = "Connection is closed (%s)." % str(exception) else: err_message = "Connection is closed." # Cursors may remove themselves when errored, so copy a list of them for cursor in list(self._cursor_cache.values()): cursor._error(err_message) for _, future in self._user_queries.values(): if not future.done(): future.set_exception(ReqlDriverError(err_message)) self._user_queries = {} self._cursor_cache = {} if noreply_wait: noreply = Query(P_QUERY.NOREPLY_WAIT, token, None, None) await self.run_query(noreply, False) try: await self._stream.aclose() except (trio.ClosedResourceError, trio.BrokenResourceError): pass # We must not wait for the _reader_task if we got an exception, because that # means that we were called from it. Waiting would lead to a deadlock. if self._reader_ended_event: await self._reader_ended_event.wait() return None
def _start(self, term, **global_optargs): # Set global opt args # The 'db' option will default to this connection's default # if not otherwise specified. if 'db' in global_optargs: global_optargs['db'] = DB(global_optargs['db']) else: if self.db: global_optargs['db'] = DB(self.db) # Construct query query = Query(pQuery.START, self.next_token, term, global_optargs) self.next_token += 1 return self._send_query(query, global_optargs)
def start_query(term, token, options): return Query(pQuery.START, token, term, options)
def _stop(self, cursor): self.check_open() q = Query(pQuery.STOP, cursor.query.token, None, None) return (yield from self._instance.run_query(q, True))
async def _stop(self, cursor): self.check_open() query = Query(P_QUERY.STOP, cursor.query.token, None, None) return await self._instance.run_query(query, True)
def end_query(self, query, opts): query = Query(pQuery.STOP, query.token, None, None) return self._send_query(query, opts)
def continue_query(self, query, opts): q = Query(pQuery.CONTINUE, query.token, None, None) return self._send_query(q, opts)