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


Python asyncore.close_all方法代码示例

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


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

示例1: closeall_check

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def closeall_check(self, usedefault):
        # Check that close_all() closes everything in a given map

        l = []
        testmap = {}
        for i in range(10):
            c = dummychannel()
            l.append(c)
            self.assertEqual(c.socket.closed, False)
            testmap[i] = c

        if usedefault:
            socketmap = asyncore.socket_map
            try:
                asyncore.socket_map = testmap
                asyncore.close_all()
            finally:
                testmap, asyncore.socket_map = asyncore.socket_map, socketmap
        else:
            asyncore.close_all(testmap)

        self.assertEqual(len(testmap), 0)

        for c in l:
            self.assertEqual(c.socket.closed, True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_asyncore.py

示例2: run

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def run(self):
        self.active = True
        self.__flag.set()
        while self.active and asyncore.socket_map:
            self.active_lock.acquire()
            asyncore.loop(timeout=0.1, count=1)
            self.active_lock.release()
        asyncore.close_all(ignore_all=True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_ftplib.py

示例3: debugging_server

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def debugging_server(serv, serv_evt, client_evt):
    serv_evt.set()

    try:
        if hasattr(select, 'poll'):
            poll_fun = asyncore.poll2
        else:
            poll_fun = asyncore.poll

        n = 1000
        while asyncore.socket_map and n > 0:
            poll_fun(0.01, asyncore.socket_map)

            # when the client conversation is finished, it will
            # set client_evt, and it's then ok to kill the server
            if client_evt.is_set():
                serv.close()
                break

            n -= 1

    except socket.timeout:
        pass
    finally:
        if not client_evt.is_set():
            # allow some time for the client to read the result
            time.sleep(0.5)
            serv.close()
        asyncore.close_all()
        serv_evt.set() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_smtplib.py

示例4: __exit__

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def __exit__(self, *args):
            if support.verbose:
                sys.stdout.write(" cleanup: stopping server.\n")
            self.stop()
            if support.verbose:
                sys.stdout.write(" cleanup: joining server thread.\n")
            self.join()
            if support.verbose:
                sys.stdout.write(" cleanup: successfully joined.\n")
            # make sure that ConnectionHandler is removed from socket_map
            asyncore.close_all(ignore_all=True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_ssl.py

示例5: tearDown

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def tearDown(self):
        asyncore.close_all() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_asyncore.py

示例6: start_server

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def start_server(self, port=2199, **kw):
        """Starts an asyncore server reading commands for clients and opening
        a new interpreter for each connection."""
        _AsynServer(self, _AsynHandler, port)  # register the server
        try:
            asyncore.loop(**kw)
        except (KeyboardInterrupt, TerminatedProcess):
            pass
        finally:
            asyncore.close_all() 
开发者ID:micheles,项目名称:plac,代码行数:12,代码来源:plac_ext.py

示例7: close

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def close(self):
        asyncore.socket_map.clear()
        asyncore.close_all() 
开发者ID:webkom,项目名称:lego,代码行数:5,代码来源:service.py

示例8: serve_forever

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def serve_forever(cls, timeout=1.0, use_poll=False, count=None):
        """A wrap around asyncore.loop(); starts the asyncore polling
        loop including running the scheduler.
        The arguments are the same expected by original asyncore.loop()
        function:

         - (float) timeout: the timeout passed to select() or poll()
           system calls expressed in seconds (default 1.0).

         - (bool) use_poll: when True use poll() instead of select()
           (default False).

         - (int) count: how many times the polling loop gets called
           before returning.  If None loops forever (default None).
        """
        if use_poll and hasattr(asyncore.select, 'poll'):
            poll_fun = asyncore.poll2
        else:
            poll_fun = asyncore.poll

        if count is None:
            log("Starting FTP server")
            try:
                try:
                    while asyncore.socket_map or _scheduler._tasks:
                        poll_fun(timeout)
                        _scheduler()
                except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
                    pass
            finally:
                log("Shutting down FTP server")
                cls.close_all()
        else:
            while (asyncore.socket_map or _scheduler._tasks) and count > 0:
                if asyncore.socket_map:
                    poll_fun(timeout)
                if _scheduler._tasks:
                    _scheduler()
                count -= 1 
开发者ID:exasol,项目名称:script-languages,代码行数:41,代码来源:ftpserver.py

示例9: close_all

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def close_all(cls, ignore_all=False):
        """Stop serving and also disconnects all currently connected
        clients.

         - (bool) ignore_all:
            having it set to False results in raising exception in case
            of unexpected errors.

        Implementation note:

        This is how asyncore.close_all() is implemented starting from
        Python 2.6.
        The previous versions of close_all() instead of iterating over
        all opened channels and calling close() method for each one
        of them only closed sockets generating memory leaks.
        """
        values = asyncore.socket_map.values()
        # We sort the list so that we close all FTP handler instances
        # first since FTPHandler.close() has the peculiarity of
        # automatically closing all its children (DTPHandler, ActiveDTP
        # and PassiveDTP).
        # This should minimize the possibility to incur in race
        # conditions or memory leaks caused by orphaned references
        # left behind in case of error.
        values.sort(key=lambda inst: isinstance(inst, FTPHandler), reverse=True)
        for x in values:
            try:
                x.close()
            except OSError, x:
                if x[0] == errno.EBADF:
                    pass
                elif not ignore_all:
                    raise
            except (asyncore.ExitNow, KeyboardInterrupt, SystemExit):
                raise 
开发者ID:exasol,项目名称:script-languages,代码行数:37,代码来源:ftpserver.py

示例10: tearDown

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import close_all [as 别名]
def tearDown(self):
        asyncore.close_all()
        asyncore.socket = smtpd.socket = socket 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_smtpd.py


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