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


Python RoutineContainer.delegateOther方法代码示例

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


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

示例1: Manager

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import delegateOther [as 别名]
class Manager(Module):
    """
    Manage module loading/unloading. Optionally reload a module when modified.
    """

    _default_checkinterval = 5
    _default_autoreload = False
    service = False

    def __init__(self, server):
        """
        Constructor
        """
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self._autoreload
        self._lastcheck = time()
        if self.autoreload:
            self.routines.append(self.apiroutine)
        self.createAPI(
            api(self.enableAutoReload),
            api(self.activeModules),
            api(self.reloadmodules, self.apiroutine),
            api(self.loadmodule, self.apiroutine),
            api(self.unloadmodule, self.apiroutine),
        )

    def activeModules(self):
        "Return current loaded modules"
        return dict((k, v.getFullPath()) for k, v in self.server.moduleloader.activeModules.items())

    def _autoreload(self):
        th = self.scheduler.setTimer(self.checkinterval, self.checkinterval)
        try:
            tm = TimerEvent.createMatcher(th)
            while True:
                yield (tm,)
                t = time()
                reloads = []
                loaded = self.activeModules().values()
                self._logger.debug("Checking loaded modules: %r", loaded)
                for k in loaded:
                    p, _ = findModule(k, False)
                    if not p or not hasattr(p, "__file__") or not p.__file__:
                        continue
                    if p.__file__.endswith(".pyc"):
                        source = p.__file__[:-1]
                    else:
                        source = p.__file__
                    try:
                        mtime = os.path.getmtime(source)
                        if mtime <= t and mtime > self._lastcheck:
                            reloads.append(k)
                    except:
                        pass
                if reloads:
                    self._logger.warning("Auto reload following modules: %r", reloads)
                    try:
                        for m in self.reloadmodules(reloads):
                            yield m
                    except:
                        self._logger.warning("Exception occurs on auto reload", exc_info=True)
                self._lastcheck = t
        finally:
            self.scheduler.cancelTimer(th)

    def loadmodule(self, path):
        """
        Load specified module
        :param path: module path (e.g. vlcp.service.connection.httpserver.HttpServer)
        """
        for m in self.apiroutine.delegateOther(self.server.moduleloader.loadByPath(path), self.server.moduleloader, ()):
            yield m
        self.apiroutine.retvalue = None

    def reloadmodules(self, pathlist):
        """
        Reload specified modules.
        :param pathlist: list of module path
        """
        for m in self.apiroutine.delegateOther(
            self.server.moduleloader.reloadModules(pathlist), self.server.moduleloader, ()
        ):
            yield m
        self.apiroutine.retvalue = None

    def unloadmodule(self, path):
        """
        Unload specified module
        :param path: module path (e.g. vlcp.service.connection.httpserver.HttpServer)
        """
        for m in self.apiroutine.delegateOther(
            self.server.moduleloader.unloadByPath(path), self.server.moduleloader, ()
        ):
            yield m
        self.apiroutine.retvalue = None

    def enableAutoReload(self, enabled=True):
        """
        Enable or disable auto reload.
#.........这里部分代码省略.........
开发者ID:hubo1016,项目名称:vlcp,代码行数:103,代码来源:modulemanager.py


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