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


Python asyncore.ExitNow方法代码示例

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


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

示例1: call

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def call(self):
        """Call this scheduled function."""
        assert not self.cancelled, "Already cancelled"
        exc = None
        try:
            try:
                self._target(*self._args, **self._kwargs)
            except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
                raise
            except Exception, exc:
                if self._errback is not None:
                    self._errback()
                else:
                    raise
        finally:
            self._post_call(exc) 
开发者ID:exasol,项目名称:script-languages,代码行数:18,代码来源:ftpserver.py

示例2: handle_error

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def handle_error(self):
        """Called when an exception is raised and not otherwise handled."""
        try:
            raise
        except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
            raise
        except socket.error, err:
            # fixes around various bugs:
            # - http://bugs.python.org/issue1736101
            # - http://code.google.com/p/pyftpdlib/issues/detail?id=104
            # - http://code.google.com/p/pyftpdlib/issues/detail?id=109
            if err.args[0] in _DISCONNECTED:
                self.handle_close()
                return
            else:
                self.log_exception(self)
                error = str(err.args[1])
        # an error could occur in case we fail reading / writing
        # from / to file (e.g. file system gets full) 
开发者ID:exasol,项目名称:script-languages,代码行数:21,代码来源:ftpserver.py

示例3: call

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def call(self):
        """Call this scheduled function."""
        assert not self.cancelled, "Already cancelled"
        try:
            try:
                self._target(*self._args, **self._kwargs)
            except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
                raise
            except:
                if self._errback is not None:
                    self._errback()
                else:
                    raise
        finally:
            if not self.cancelled:
                self.cancel() 
开发者ID:ActiveState,项目名称:code,代码行数:18,代码来源:recipe-577808.py

示例4: handle_read_event

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

示例5: test_readwriteexc

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def test_readwriteexc(self):
        # Check exception handling behavior of read, write and _exception

        # check that ExitNow exceptions in the object handler method
        # bubbles all the way up through asyncore read/write/_exception calls
        tr1 = exitingdummy()
        self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
        self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
        self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)

        # check that an exception other than ExitNow in the object handler
        # method causes the handle_error method to get called
        tr2 = crashingdummy()
        asyncore.read(tr2)
        self.assertEqual(tr2.error_handled, True)

        tr2 = crashingdummy()
        asyncore.write(tr2)
        self.assertEqual(tr2.error_handled, True)

        tr2 = crashingdummy()
        asyncore._exception(tr2)
        self.assertEqual(tr2.error_handled, True)

    # asyncore.readwrite uses constants in the select module that
    # are not present in Windows systems (see this thread:
    # http://mail.python.org/pipermail/python-list/2001-October/109973.html)
    # These constants should be present as long as poll is available 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_asyncore.py

示例6: _do_REBOOT

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def _do_REBOOT(self, params):
        raise asyncore.ExitNow('Server is rebooting!') 
开发者ID:SafeBreach-Labs,项目名称:backdoros,代码行数:4,代码来源:backdoros.py

示例7: _do_SHUTDOWN

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def _do_SHUTDOWN(self, params):
        global _is_alive
        _is_alive = False
        raise asyncore.ExitNow('Server is quitting!') 
开发者ID:SafeBreach-Labs,项目名称:backdoros,代码行数:6,代码来源:backdoros.py

示例8: __call__

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def __call__(self):
        now = time.time()
        calls = []
        while self._tasks:
            if now < self._tasks[0].timeout:
                break
            call = heapq.heappop(self._tasks)
            if not call.cancelled:
                calls.append(call)
            else:
                self._cancellations -= 1

        for call in calls:
            if call._repush:
                heapq.heappush(self._tasks, call)
                call._repush = False
                continue
            try:
                call.call()
            except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
                raise
            except:
                logerror(traceback.format_exc())

        # remove cancelled tasks and re-heapify the queue if the
        # number of cancelled tasks is more than the half of the
        # entire queue
        if self._cancellations > 512 \
          and self._cancellations > (len(self._tasks) >> 1):
            self._cancellations = 0
            self._tasks = [x for x in self._tasks if not x.cancelled]
            self.reheapify() 
开发者ID:exasol,项目名称:script-languages,代码行数:34,代码来源:ftpserver.py

示例9: serve_forever

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [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

示例10: close_all

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [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

示例11: _scheduler

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def _scheduler():
    """Run the scheduled functions due to expire soonest (if any)."""
    now = time.time()
    while _tasks and now >= _tasks[0].timeout:
        call = heapq.heappop(_tasks)
        if call._repush:
            heapq.heappush(_tasks, call)
            call._repush = False
            continue
        try:
            call.call()
        except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
            raise
        except:
            print traceback.format_exc() 
开发者ID:ActiveState,项目名称:code,代码行数:17,代码来源:recipe-577808.py

示例12: close_all

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import ExitNow [as 别名]
def close_all(map=None, ignore_all=False):
    """Close all scheduled functions and opened sockets."""
    if map is None:
        map = asyncore.socket_map
    for x in map.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:ActiveState,项目名称:code,代码行数:16,代码来源:recipe-577808.py


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