Exemplo n.º 1
0
 def _poll_connection(self, port_name, timeout=0):
     """ Repeatedly attempt to open a connection to a Bolt server.
     """
     t0 = monotonic()
     profile = self.profiles[port_name]
     log.debug("Trying to open connection to %s", profile)
     errors = set()
     again = True
     wait = 0.1
     while again:
         try:
             cx = Connection.open(profile)
         except InvalidVersion as e:
             log.info(
                 "Encountered invalid Neo4j version '%s'. Continuing anyway (this is a dev tool)",
                 e)
             return None
         except ConnectionUnavailable as e:
             errors.add(" ".join(map(str, e.args)))
         else:
             if cx:
                 return cx
         again = monotonic() - t0 < (timeout or 0)
         if again:
             sleep(wait)
             wait *= 2
     log.error("Could not open connection to %s (%r)", profile, errors)
     raise ConnectionUnavailable("Could not open connection")
Exemplo n.º 2
0
 def __init__(self, profile=None, **settings):
     profile = _ConnectionProfile(profile, **settings)
     try:
         self._cx = _Connection.open(profile)
     except _ConnectionUnavailable as error:
         raise_from(self.OperationalError("Connection unavailable"), error)
     self._tx = None
     self._db = None
Exemplo n.º 3
0
def connection(connection_profile):
    cx = Connection.open(connection_profile)
    yield cx
    cx.close()
Exemplo n.º 4
0
def connection(service_profile):
    cx = Connection.open(service_profile)
    yield cx
    cx.close()