当前位置: 首页>>代码示例>>Python>>正文


Python GreenSocket.setblocking方法代码示例

本文整理汇总了Python中eventlet.greenio.GreenSocket.setblocking方法的典型用法代码示例。如果您正苦于以下问题:Python GreenSocket.setblocking方法的具体用法?Python GreenSocket.setblocking怎么用?Python GreenSocket.setblocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eventlet.greenio.GreenSocket的用法示例。


在下文中一共展示了GreenSocket.setblocking方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
    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,代码行数:27,代码来源:geventlet.py

示例2: EventletWorker

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
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,代码行数:35,代码来源:geventlet.py

示例3: run

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
    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,代码行数:29,代码来源:geventlet.py

示例4: EventletWorker

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
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,代码行数:61,代码来源:geventlet.py

示例5: Worker

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
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,代码行数:18,代码来源:worker.py

示例6: run

# 需要导入模块: from eventlet.greenio import GreenSocket [as 别名]
# 或者: from eventlet.greenio.GreenSocket import setblocking [as 别名]
    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,代码行数:22,代码来源:geventlet.py


注:本文中的eventlet.greenio.GreenSocket.setblocking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。