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


Python greenio.GreenSocket類代碼示例

本文整理匯總了Python中eventlet.greenio.GreenSocket的典型用法代碼示例。如果您正苦於以下問題:Python GreenSocket類的具體用法?Python GreenSocket怎麽用?Python GreenSocket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: __init__

    def __init__(
        self,
        sock,
        keyfile=None,
        certfile=None,
        server_side=False,
        cert_reqs=CERT_NONE,
        ssl_version=PROTOCOL_SSLv23,
        ca_certs=None,
        do_handshake_on_connect=True,
        *args,
        **kw
    ):
        if not isinstance(sock, GreenSocket):
            sock = GreenSocket(sock)

        self.act_non_blocking = sock.act_non_blocking

        if six.PY2:
            # On Python 2 SSLSocket constructor queries the timeout, it'd break without
            # this assignment
            self._timeout = sock.gettimeout()

        # nonblocking socket handshaking on connect got disabled so let's pretend it's disabled
        # even when it's on
        super(GreenSSLSocket, self).__init__(
            sock.fd,
            keyfile,
            certfile,
            server_side,
            cert_reqs,
            ssl_version,
            ca_certs,
            do_handshake_on_connect and six.PY2,
            *args,
            **kw
        )

        # the superclass initializer trashes the methods so we remove
        # the local-object versions of them and let the actual class
        # methods shine through
        # Note: This for Python 2
        try:
            for fn in orig_socket._delegate_methods:
                delattr(self, fn)
        except AttributeError:
            pass

        if six.PY3:
            # Python 3 SSLSocket construction process overwrites the timeout so restore it
            self._timeout = sock.gettimeout()

            # it also sets timeout to None internally apparently (tested with 3.4.2)
            _original_sslsocket.settimeout(self, 0.0)
            assert _original_sslsocket.gettimeout(self) == 0.0

            # see note above about handshaking
            self.do_handshake_on_connect = do_handshake_on_connect
            if do_handshake_on_connect and self._connected:
                self.do_handshake()
開發者ID:simudream,項目名稱:eventlet,代碼行數:60,代碼來源:ssl.py

示例2: run

    def run(self):
        acceptors = []
        for sock in self.sockets:
            gsock = GreenSocket(sock)
            gsock.setblocking(1)
            hfun = partial(self.handle, gsock)
            acceptor = eventlet.spawn(_eventlet_serve, gsock, hfun,
                                      self.worker_connections)

            acceptors.append(acceptor)
            eventlet.sleep(0.0)

        while self.alive:
            self.notify()
            eventlet.sleep(1.0)

        self.notify()
        try:
            with eventlet.Timeout(self.cfg.graceful_timeout) as t:
                [a.kill(eventlet.StopServe()) for a in acceptors]
                [a.wait() for a in acceptors]
        except eventlet.Timeout as te:
            if te != t:
                raise
            [a.kill() for a in acceptors]
開發者ID:Aayush-N,項目名稱:aynst,代碼行數:25,代碼來源:geventlet.py

示例3: EventletWorker

class EventletWorker(AsyncWorker):

    @classmethod
    def setup(cls):
        import eventlet
        if eventlet.version_info < (0,9,7):
            raise RuntimeError("You need eventlet >= 0.9.7")
        eventlet.monkey_patch(os=False)

    def init_process(self):
        hubs.use_hub()
        super(EventletWorker, self).init_process()

    def timeout_ctx(self):
        return eventlet.Timeout(self.cfg.keepalive, False)

    def run(self):
        self.socket = GreenSocket(family_or_realsock=self.socket.sock)
        self.socket.setblocking(1)
        self.acceptor = eventlet.spawn(eventlet.serve, self.socket,
                self.handle, self.worker_connections)

        while self.alive:
            self.notify()
            if self.ppid != os.getppid():
                self.log.info("Parent changed, shutting down: %s", self)
                break

            eventlet.sleep(1.0)

        self.notify()
        with eventlet.Timeout(self.timeout, False):
            eventlet.kill(self.acceptor, eventlet.StopServe)
開發者ID:DenerosArmy,項目名稱:wing,代碼行數:33,代碼來源:geventlet.py

示例4: run

    def run(self):
        acceptors = []
        for sock in self.sockets:
            s = GreenSocket(family_or_realsock=sock)
            s.setblocking(1)
            hfun = partial(self.handle, s)
            acceptor = eventlet.spawn(eventlet.serve, s, hfun,
                    self.worker_connections)

            acceptors.append(acceptor)

        while self.alive:
            self.notify()
            if self.ppid != os.getppid():
                self.log.info("Parent changed, shutting down: %s", self)
                break

            eventlet.sleep(1.0)

        self.notify()
        try:
            with eventlet.Timeout(self.cfg.graceful_timeout) as t:
                [a.wait() for a in acceptors]
        except eventlet.Timeout as te:
            if te != t:
                raise
            [a.kill() for a in acceptors]
開發者ID:CoderDojoSV,項目名稱:CoderDojoSV-1.0,代碼行數:27,代碼來源:geventlet.py

示例5: EventletWorker

class EventletWorker(AsyncWorker):

    @classmethod
    def setup(cls):
        import eventlet
        if eventlet.version_info < (0,9,7):
            raise RuntimeError("You need eventlet >= 0.9.7")
        eventlet.monkey_patch(os=False)
    
    def init_process(self):
        hubs.use_hub()
        super(EventletWorker, self).init_process()
        
    def timeout_ctx(self):
        return eventlet.Timeout(self.cfg.keepalive, False)

    def acceptor(self, pool):
        try:
            while self.alive:
                try:
                    client, addr = self.socket.accept()
                    pool.spawn_n(self.handle, client, addr)
                except socket.error, e:
                    if e[0] not in (errno.EAGAIN, errno.ECONNABORTED):
                        raise

                if pool.running() > self.worker_connections:
                    continue
                           
                try:
                    hubs.trampoline(self.socket.fileno(), read=True,
                        timeout=self.timeout)
                except eventlet.Timeout:
                    pass
        except eventlet.StopServer:
            pool.waitall()

    def run(self):
        self.socket = GreenSocket(family_or_realsock=self.socket.sock)
        self.socket.setblocking(1)

        pool = eventlet.GreenPool(self.worker_connections)

        acceptor = eventlet.spawn(self.acceptor, pool)

        try:
            while self.alive:
                self.notify()
            
                if self.ppid != os.getppid():
                    self.log.info("Parent changed, shutting down: %s" % self)
                    server.stop()
                    break
                eventlet.sleep(0.1) 
        except KeyboardInterrupt:
            pass

        with eventlet.Timeout(self.timeout, False):
            eventlet.kill(acceptor, eventlet.StopServe)
開發者ID:batok,項目名稱:gunicorn,代碼行數:59,代碼來源:geventlet.py

示例6: __init__

    def __init__(self, sock, *args, **kw):
        if not isinstance(sock, GreenSocket):
            sock = GreenSocket(sock)

        self.act_non_blocking = sock.act_non_blocking
        self._timeout = sock.gettimeout()
        super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw)
       
        # the superclass initializer trashes the methods so... 
        for fn in orig_socket._delegate_methods:
            delattr(self, fn)
開發者ID:JeremyGrosser,項目名稱:python-eventlet,代碼行數:11,代碼來源:ssl.py

示例7: __init__

    def __init__(self, sock, *args, **kw):
        if not isinstance(sock, GreenSocket):
            sock = GreenSocket(sock)

        self.act_non_blocking = sock.act_non_blocking
        self._timeout = sock.gettimeout()
        super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw)
       
        # the superclass initializer trashes the methods so we remove
        # the local-object versions of them and let the actual class
        # methods shine through
        try:
            for fn in orig_socket._delegate_methods:
                delattr(self, fn)
        except AttributeError:
            pass
開發者ID:simplegeo,項目名稱:eventlet,代碼行數:16,代碼來源:ssl.py

示例8: Worker

class Worker(object):

    def __init__(self, sock):
        self.socket = sock

    def init_worker(self):
        hubs.use_hub()

    def run(self):
        self.socket = GreenSocket(family_or_realsock=self.socket.sock)
        self.socket.setblocking(1)
        self.acceptor = eventlet.spawn(eventlet.serve, self.socket, server.handle, int(config.get("MAX_CONNECTIONS")))
        while True:
            eventlet.sleep(0.1)
        with eventlet.Timeout(30, False):
            eventlet.kill(self.acceptor, eventlet.StopServe)
開發者ID:dahabit,項目名稱:liasis,代碼行數:16,代碼來源:worker.py

示例9: run

 def run(self):
     self.socket = GreenSocket(family_or_realsock=self.socket.sock)
     self.socket.setblocking(1)
     self.acceptor = eventlet.spawn(eventlet.serve, self.socket, server.handle, int(config.get("MAX_CONNECTIONS")))
     while True:
         eventlet.sleep(0.1)
     with eventlet.Timeout(30, False):
         eventlet.kill(self.acceptor, eventlet.StopServe)
開發者ID:dahabit,項目名稱:liasis,代碼行數:8,代碼來源:worker.py

示例10: run

    def run(self):
        acceptors = []
        for sock in self.sockets:
            s = GreenSocket(family_or_realsock=sock)
            s.setblocking(1)
            hfun = partial(self.handle, s)
            acceptor = eventlet.spawn(eventlet.serve, s, hfun,
                    self.worker_connections)

        while self.alive:
            self.notify()
            if self.ppid != os.getppid():
                self.log.info("Parent changed, shutting down: %s", self)
                break

            eventlet.sleep(1.0)

        self.notify()
        with eventlet.Timeout(self.cfg.graceful_timeout, False):
            [eventlet.kill(a, eventlet.StopServe) for a in acceptors]
開發者ID:gaiyangjun,項目名稱:gunicorn,代碼行數:20,代碼來源:geventlet.py

示例11: run

    def run(self):
        self.socket = GreenSocket(family_or_realsock=self.socket.sock)
        self.socket.setblocking(1)
        self.acceptor = eventlet.spawn(eventlet.serve, self.socket,
                self.handle, self.worker_connections)

        while self.alive:
            self.notify()
            if self.ppid != os.getppid():
                self.log.info("Parent changed, shutting down: %s" % self)
                break
            eventlet.sleep(0.1)

        self.notify()
        with eventlet.Timeout(self.timeout, False):
            eventlet.kill(self.acceptor, eventlet.StopServe)
開發者ID:brtsz,項目名稱:gunicorn,代碼行數:16,代碼來源:geventlet.py

示例12: run

    def run(self):
        self.socket = GreenSocket(family_or_realsock=self.socket.sock)
        self.socket.setblocking(1)

        pool = eventlet.GreenPool(self.worker_connections)

        acceptor = eventlet.spawn(self.acceptor, pool)

        try:
            while self.alive:
                self.notify()
            
                if self.ppid != os.getppid():
                    self.log.info("Parent changed, shutting down: %s" % self)
                    server.stop()
                    break
                eventlet.sleep(0.1) 
        except KeyboardInterrupt:
            pass

        with eventlet.Timeout(self.timeout, False):
            eventlet.kill(acceptor, eventlet.StopServe)
開發者ID:batok,項目名稱:gunicorn,代碼行數:22,代碼來源:geventlet.py


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