网络中的任务调度?
你能推荐一个可以在网络中远程机器上安排任务的 python
工具或模块吗?
需要注意的是,这个解决方案不仅要能在远程机器上运行特定的工作或命令,还要能检查这些工作是否仍在运行(比如,想象一下如果一台机器在任务分配后死掉了,会发生什么?)
3 个回答
0
应该可以使用 Python WMI,对于基于*NIX的系统,它是一个关于SSH和CRON的 封装。
2
Fabric(http://docs.fabfile.org/en/1.0.1/index.html)是一个非常不错的工具包,专门用来处理系统管理和部署的各种任务。它自带了一些预设的任务,但也允许你根据自己的需要添加新的任务。
我非常推荐这个工具。
3
RPyC,也就是远程Python调用,是一个透明且对称的Python库,用于远程过程调用、集群和分布式计算。下面是来自维基百科的一个例子:
import rpyc
conn = rpyc.classic.connect("hostname") # assuming a classic server is running on 'hostname'
print conn.modules.sys.path
conn.modules.sys.path.append("lucy")
print conn.modules.sys.path[-1]
# a version of 'ls' that runs remotely
def remote_ls(path):
ros = conn.modules.os
for filename in ros.listdir(path):
stats = ros.stat(ros.path.join(path, filename))
print "%d\t%d\t%s" % (stats.st_size, stats.st_uid, filename)
remote_ls("/usr/bin")
# and exceptions...
try:
f = conn.builtin.open("/non/existent/file/name")
except IOError:
pass
如果你想检查远程服务器在被分配任务后是否还活着,可以使用连接类中的ping方法。完整的API说明可以在这里找到。