當前位置: 首頁>>代碼示例>>Python>>正文


Python LightQueue.put_nowait方法代碼示例

本文整理匯總了Python中eventlet.queue.LightQueue.put_nowait方法的典型用法代碼示例。如果您正苦於以下問題:Python LightQueue.put_nowait方法的具體用法?Python LightQueue.put_nowait怎麽用?Python LightQueue.put_nowait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eventlet.queue.LightQueue的用法示例。


在下文中一共展示了LightQueue.put_nowait方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: EventletConnectionPool

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put_nowait [as 別名]
class EventletConnectionPool(ConnectionPool):
    def __init__(self, connection_class=Connection, max_connections=None,
                 **connection_kwargs):
        self.pid = os.getpid()
        self.connection_class = connection_class
        self.connection_kwargs = connection_kwargs
        self.max_connections = max_connections or 2 ** 31
        self._created_connections = 0
        self._available_connections = LightQueue()
        self._in_use_connections = set()
    def get_connection(self, command_name, *keys, **options):
        "Get a connection from the pool"
        try:
            connection = self._available_connections.get_nowait()
        except Empty:
            if self._created_connections < self.max_connections:
                connection = self.make_connection()
            else:
                try:
                    connection = self._available_connections.get()
                except Empty:
                    raise ConnectionError("Couldn't find a free connection")
        self._in_use_connections.add(connection)
        return connection
    def release(self, connection):
        "Releases the connection back to the pool"
        self._checkpid()
        if connection.pid == self.pid:
            self._in_use_connections.remove(connection)
            self._available_connections.put_nowait(connection)
    def disconnect(self):
        "Disconnects all connections in the pool"
        while True:
            try:
                self._available_connections.get_nowait().disconnect()
            except Empty:
                break
        for connection in self._in_use_connections:
            connection.disconnect()
開發者ID:jinktv,項目名稱:django-cache-magic,代碼行數:41,代碼來源:client.py

示例2: Supervisor

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put_nowait [as 別名]

#.........這裏部分代碼省略.........
        gThread.__init__(self)
        Status.__init__(self)

    def __copy__(self):
        return self.__class__(self.interval, self._orig_queue_arg)

    def pause(self):
        """Pause all timers."""
        self.respond_to_ping()
        with self._pause_mutex:
            if not self.paused:
                self.debug('pausing')
                self.paused = True

    def resume(self):
        """Resume all timers."""
        with self._pause_mutex:
            if self.paused:
                self.debug('resuming')
                self.paused = False

    def verify(self, instances, ratelimit=False):
        """Verify the consistency of one or more instances.

        :param instances: List of instances to verify.

        This operation is asynchronous, and returns a :class:`Greenlet`
        instance that can be used to wait for the operation to complete.

        """
        return self._request(instances, self._do_verify_instance,
                            {'ratelimit': ratelimit})

    def restart(self, instances):
        """Restart one or more instances.

        :param instances: List of instances to restart.

        This operation is asynchronous, and returns a :class:`Greenlet`
        instance that can be used to wait for the operation to complete.

        """
        return self._request(instances, self._do_restart_instance)

    def shutdown(self, instances):
        """Shutdown one or more instances.

        :param instances: List of instances to stop.

        This operation is asynchronous, and returns a :class:`Greenlet`
        instance that can be used to wait for the operation to complete.

        .. warning::

            Note that the supervisor will automatically restart
            any stopped instances unless the corresponding :class:`Instance`
            model has been marked as disabled.

        """
        return self._request(instances, self._do_stop_instance)

    def _request(self, instances, action, kwargs={}):
        event = Event()
        self.queue.put_nowait((instances, event, action, kwargs))
        return event

    def before(self):
        self.start_periodic_timer(self.interval, self._verify_all)

    def run(self):
        queue = self.queue
        self.info('started')
        supervisor_ready.send(sender=self)
        while not self.should_stop:
            try:
                instances, event, action, kwargs = queue.get(timeout=1)
            except Empty:
                self.respond_to_ping()
                continue
            self.respond_to_ping()
            self.debug('wake-up')
            try:
                for instance in instances:
                    try:
                        action(instance, **kwargs)
                    except Exception, exc:
                        self.error('Event caused exception: %r', exc)
            finally:
                event.send(True)

    def _verify_all(self, force=False):
        if self._last_update and self._last_update.ready():
            try:
                self._last_update.wait()  # collect result
            except self.GreenletExit:
                pass
            force = True
        if not self._last_update or force:
            self._last_update = self.verify(self.all_instances(),
                                            ratelimit=True)
開發者ID:adamchainz,項目名稱:cyme,代碼行數:104,代碼來源:supervisor.py


注:本文中的eventlet.queue.LightQueue.put_nowait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。