dddp/postgres.py
def _run(self):  # pylint: disable=method-hidden
        """Spawn sub tasks, wait for stop signal."""
        conn_params = self.connection.get_connection_params()
        # See http://initd.org/psycopg/docs/module.html#psycopg2.connect and
        # http://www.postgresql.org/docs/current/static/libpq-connect.html
        # section 31.1.2 (Parameter Key Words) for details on available params.
        conn_params.update(
            async=True,
            application_name='{} pid={} django-ddp'.format(
                socket.gethostname(),  # hostname
                os.getpid(),  # PID
            )[:64],  # 64 characters for default PostgreSQL build config
        )
        conn = None
        while conn is None:
            try:
                conn = psycopg2.connect(**conn_params)
            except psycopg2.OperationalError as err:
                # Some variants of the psycopg2 driver for Django add extra
                # params that aren't meant to be passed directly to
                # `psycopg2.connect()` -- issue a warning and try again.
                msg = ('%s' % err).strip()
                msg_prefix = 'invalid connection option "'
                if not msg.startswith(msg_prefix):
                    # *waves hand* this is not the errror you are looking for.
                    raise
                key = msg[len(msg_prefix):-1]
                self.logger.warning(
                    'Ignoring unknown settings.DATABASES[%r] option: %s=%r',
                    self.connection.alias,
                    key, conn_params.pop(key),
                )
        self.poll(conn)  # wait for conneciton to start

        import logging
        logging.getLogger('dddp').info('=> Started PostgresGreenlet.')

        cur = conn.cursor()
        cur.execute('LISTEN "ddp";')
        while not self._stop_event.is_set():
            try:
                self.select_greenlet = gevent.spawn(
                    gevent.select.select,
                    [conn], [], [], timeout=None,
                )
                self.select_greenlet.get()
            except gevent.GreenletExit:
                self._stop_event.set()
            finally:
                self.select_greenlet = None
            self.poll(conn)
        self.poll(conn)
        cur.close()
        self.poll(conn)
        conn.close()
def _run(self):  # pylint: disable=method-hidden
        conn_params = self.connection.get_connection_params()
        # See http://initd.org/psycopg/docs/module.html#psycopg2.connect and
        # http://www.postgresql.org/docs/current/static/libpq-connect.html
        # section 31.1.2 (Parameter Key Words) for details on available params.
        conn_params.update(
            async=True,
            application_name='{} pid={} django-ddp'.format(
                socket.gethostname(),  # hostname
                os.getpid(),  # PID
            )[:64],  # 64 characters for default PostgreSQL build config
        )
        conn = None
        while conn is None:
            try:
                conn = psycopg2.connect(**conn_params)
            except psycopg2.OperationalError as err:
                # Some variants of the psycopg2 driver for Django add extra
                # params that aren't meant to be passed directly to
                # `psycopg2.connect()` -- issue a warning and try again.
                msg = ('%s' % err).strip()
                msg_prefix = 'invalid connection option "'
                if not msg.startswith(msg_prefix):
                    # *waves hand* this is not the errror you are looking for.
                    raise
                key = msg[len(msg_prefix):-1]
                self.logger.warning(
                    'Ignoring unknown settings.DATABASES[%r] option: %s=%r',
                    self.connection.alias,
                    key, conn_params.pop(key),
                )
        self.poll(conn)  # wait for conneciton to start

        import logging
        logging.getLogger('dddp').info('=> Started PostgresGreenlet.')

        cur = conn.cursor()
        cur.execute('LISTEN "ddp";')
        while not self._stop_event.is_set():
            try:
                self.select_greenlet = gevent.spawn(
                    gevent.select.select,
                    [conn], [], [], timeout=None,
                )
                self.select_greenlet.get()
            except gevent.GreenletExit:
                self._stop_event.set()
            finally:
                self.select_greenlet = None
            self.poll(conn)
        self.poll(conn)
        cur.close()
        self.poll(conn)
        conn.close()
def _run ( self ) : # pylint: disable=method-hidden conn_params = self . connection . get_connection_params ( ) # See http://initd.org/psycopg/docs/module.html#psycopg2.connect and # http://www.postgresql.org/docs/current/static/libpq-connect.html # section 31.1.2 (Parameter Key Words) for details on available params. conn_params . update ( async = True , application_name = '{} pid={} django-ddp' . format ( socket . gethostname ( ) , # hostname os . getpid ( ) , # PID ) [ : 64 ] , # 64 characters for default PostgreSQL build config ) conn = None while conn is None : try : conn = psycopg2 . connect ( * * conn_params ) except psycopg2 . OperationalError as err : # Some variants of the psycopg2 driver for Django add extra # params that aren't meant to be passed directly to # `psycopg2.connect()` -- issue a warning and try again. msg = ( '%s' % err ) . strip ( ) msg_prefix = 'invalid connection option "' if not msg . startswith ( msg_prefix ) : # *waves hand* this is not the errror you are looking for. raise key = msg [ len ( msg_prefix ) : - 1 ] self . logger . warning ( 'Ignoring unknown settings.DATABASES[%r] option: %s=%r' , self . connection . alias , key , conn_params . pop ( key ) , ) self . poll ( conn ) # wait for conneciton to start import logging logging . getLogger ( 'dddp' ) . info ( '=> Started PostgresGreenlet.' ) cur = conn . cursor ( ) cur . execute ( 'LISTEN "ddp";' ) while not self . _stop_event . is_set ( ) : try : self . select_greenlet = gevent . spawn ( gevent . select . select , [ conn ] , [ ] , [ ] , timeout = None , ) self . select_greenlet . get ( ) except gevent . GreenletExit : self . _stop_event . set ( ) finally : self . select_greenlet = None self . poll ( conn ) self . poll ( conn ) cur . close ( ) self . poll ( conn ) conn . close ( )
Spawn sub tasks, wait for stop signal.
Spawn sub tasks wait for stop signal .