Get a singleton global connection or set it up if not already set up.
489422
public static function getConnection() {
        global $PDOX, $CFG;

        if ( isset($PDOX) && is_object($PDOX) && get_class($PDOX) == 'Tsugi\Util\PDOX' ) {
            return $PDOX;
        }

        if ( defined('PDO_WILL_CATCH') ) {
            $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
            $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        } else {
            try {
                $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
                $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            } catch(\PDOException $ex){
                error_log("DB connection: ".$ex->getMessage());
                die('Failure connecting to the database, see error log'); // with error_log
            }
        }
        if ( isset($CFG->slow_query) ) $PDOX->slow_query = $CFG->slow_query;
        return $PDOX;
    }
166581
def connect(self):
        '''
        
        '''
        if self.connected:
            raise RuntimeError(
                '{} is connected already'.format(self.__class__.__name__))
        if self.closed:
            raise RuntimeError(
                '{} is closed already'.format(self.__class__.__name__))
        self.connected = True
        self._connect()
71965
def get_connection_cls(cls):
        
        if cls.__connection_cls is None:
            cls.__connection_cls, _ = cls.from_settings()
        return cls.__connection_cls
869568
def get_instance(cls):
        
        if not cls.prepared:
            raise SingletonNotPreparedError(
                "prepare must be called before get_instance"
            )

        if hasattr(cls.local, 'tchannel') and cls.local.tchannel is not None:
            return cls.local.tchannel

        cls.local.tchannel = cls.tchannel_cls(*cls.args, **cls.kwargs)

        return cls.local.tchannel
673557
def make_connection(self):
        ""
        connection = self.connection_class(**self.connection_kwargs)
        self._connections.append(connection)
        return connection
846622
def get_conn(self, *args, **kwargs):
        
        connections = self.__connections_for('get_conn', args=args, kwargs=kwargs)

        if len(connections) is 1:
            return connections[0]
        else:
            return connections
139296
def get_ldap(cls, global_options=None):
        
        # Apply global LDAP options once
        if not cls._ldap_configured and global_options is not None:
            for opt, value in global_options.items():
                ldap.set_option(opt, value)

            cls._ldap_configured = True

        return ldap
649842
def connection(self, name=None):
        
        name, type = self._parse_connection_name(name)

        if name not in self._connections:
            logger.debug("Initiating connection %s" % name)
            connection = self._make_connection(name)

            self._set_connection_for_type(connection, type)

            self._connections[name] = self._prepare(connection)

        return self._connections[name]
1016864
def connect(self, origin=None):
        
        self.logger.debug('Establish connection...')

        if self.connected:
            self.logger.warning('Connection already established. Return...')
            return

        if origin is not None:
            self.origin = origin

        self.auto_reconnect = True

        self.ws_thread = threading.Thread(
            name="APIConnectionThread_{}".format(uuid.uuid1()),
            target=self._run_forever)
        self.ws_thread.daemon = True
        self.ws_thread.start()
160405
def getInstance(cls, *args):
        '''
        
        '''
        if not cls.__singleton:
            cls.__singleton = DriverManager(*args)
        return cls.__singleton
1042858
def make_connection(self):
        """"""
        if self._created_connections[self._pattern_idx] >= self.max_connections_per_pattern:
            raise ConnectionError("Too many connections")
        self._created_connections[self._pattern_idx] += 1
        conn = self.connection_class(**self.patterns[self._pattern_idx])
        conn._pattern_idx = self._pattern_idx
        return conn
1182798
def global_instance(cls, cmdline_args, allow_override=False):
        
        orig_value = cls._instance
        assert (orig_value is None) or allow_override
        new_value = None
        try:
            new_value = CmdlineParser(cmdline_args)
            cls._instance = new_value
            yield new_value
        finally:
            assert cls._instance is new_value
            cls._instance = orig_value
913301
static synchronized Udev getInstance() {
        if (instance == null) {
            try {
                instance = new Udev();
            } catch (IOException e) {
                System.err.println("Udev: failed to open connection");
                e.printStackTrace();
            }
        }
        return instance;
    }
1082343
private Connection getConn() {
        Connection connection = localConnection.get();
        return ifNotNullReturn(connection, connection, this.getSql2o().open());
    }
594212
def connect(*args, **kwargs):
    """"""
    from .connections import Connection
    conn = Connection(*args, **kwargs)
    yield conn.connect()
    raise gen.Return(conn)
1212673
def getInstance(cls, *args):
        '''
        
        '''
        if not cls.__singleton:
            cls.__singleton = Config(*args)
        return cls.__singleton
775656
def from_global_driver(self):
        """"""
        address, _ = _read_driver()

        if address is None:
            raise DriverNotRunningError("No driver currently running")

        security = Security.from_default()
        return Client(address=address, security=security)