本文整理汇总了Python中vlcp.event.runnable.RoutineContainer.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python RoutineContainer.terminate方法的具体用法?Python RoutineContainer.terminate怎么用?Python RoutineContainer.terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vlcp.event.runnable.RoutineContainer
的用法示例。
在下文中一共展示了RoutineContainer.terminate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Manager
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import terminate [as 别名]
#.........这里部分代码省略.........
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.
:param enabled: enable if True, disable if False
"""
enabled_now = self.apiroutine in self.routines
if enabled != enabled_now:
if enabled:
self.apiroutine.start()
self.routines.append(self.apiroutine)
else:
self.apiroutine.terminate()
self.routines.remove(self.apiroutine)
return None