當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。