本文整理汇总了Python中configuration.Configuration.getint方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.getint方法的具体用法?Python Configuration.getint怎么用?Python Configuration.getint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.getint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getint [as 别名]
class Job:
""" Represents a job. Starts flof.py and connects to it. """
_connection = None
_child_proc = None
def __init__(self, prio, config):
self.prio = int(prio)
self.config = Configuration(config)
self.jid = generate_jid()
def run(self):
""" Runs the job asynchronously by calling 'flof.py --no-run config_file'. """
assert self.state == ST_QUEUED
self._child_proc = subprocess.Popen(["flof.py", "--no-run", self.config.case_config])
time.sleep(2) # Wait some seconds to allow server to start
logger.info("Job %s started: %s", str(self.jid), self.config.case_config)
self._connection = xmlrpclib.ServerProxy("http://localhost:%i/" %
self.config.getint("general", "slave_port"),
allow_none = True)
try:
self._connection.run()
except:
logger.warning("Exception raised while running the flof client. This may happen if a run is aborted.")
@property
def state(self):
if self._child_proc == None:
return ST_QUEUED
elif self._child_proc.poll() == None:
return ST_RUNNING
elif self._child_proc.returncode == ST_ABORTED:
return ST_ABORTED
elif self._child_proc.returncode == 0:
return ST_FINISHED
elif self._child_proc.returncode != 0:
return ST_FAILED
def abort(self, force=False):
""" Aborts the job. If force is True the process is simply killed. Otherwise a XML-RPC call to abort is send. """
if force:
if self._child_proc and not self._child_proc.poll():
self._child_proc.kill()
else:
try:
self._connection.abort()
except:
pass
def active_worker(self):
""" Returns the name of the currently active worker. """
try:
return self._connection.active_worker()
except:
return "" # Return None??
def worker_info(self):
""" A dictionary with information that is specific to the currently running worker. """
try:
return self._connection.worker_info()
except:
return {}
def as_dict(self):
""" Dictionary with job specific information. """
return {
"jid": self.jid,
"prio": self.prio,
"config": self.config.case_config,
"state": self.state,
"active_worker" : self.active_worker(),
"worker_info" : self.worker_info()
}
示例2: Configuration
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getint [as 别名]
#!/usr/bin/python2
import xmlrpclib, sys
from common import norm_path, state2str, ST_RUNNING
from configuration import Configuration
config = Configuration()
port = config.getint("general", "server_port")
proxy = xmlrpclib.ServerProxy("http://localhost:%i/" % port, allow_none = True)
def list_queue():
""" Gives a list of enquened jobs and their status. """
queue = proxy.get_queue()
print "Queue State: ", state2str(proxy.queue_state())
print "Queue Size: ", len(queue)
print ""
fmt_str = "{jid!s:8}{config:60}{prio!s:10}{state:5}"
run_fmt_str = " Active Worker: {active_worker:44} Worker Information: {worker_info}"
print fmt_str.format(jid="Job ID", config="Configuration File", prio="Priority", state="State")
print "---------------------------------------------------------------------------------------"
for i in queue:
state = i["state"]
i["state"] = state2str(i["state"])
print fmt_str.format(**i)
if state == ST_RUNNING:
print run_fmt_str.format(**i)