本文整理汇总了Python中job.Job.start方法的典型用法代码示例。如果您正苦于以下问题:Python Job.start方法的具体用法?Python Job.start怎么用?Python Job.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类job.Job
的用法示例。
在下文中一共展示了Job.start方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: routine
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
def routine(self):
self.assert_environment_prerequisite()
# clean up finished jobs
self.stop_tracking_terminated_jobs()
# get job actions
try:
job_actions = self.jrds_client.get_job_actions(self.sandbox_id)
except JrdsSandboxTerminated:
tracer.log_sandbox_jrds_closure_request()
global routine_loop
routine_loop = False
return
for job_action in job_actions:
job_id = job_action["JobId"]
job_data = self.jrds_client.get_job_data(job_id)
job_pending_action = job_data.pending_action
job_status = job_data.job_status
# issue pending action
if job_pending_action == pendingactions.ACTIVATE_ENUM_INDEX or \
(job_pending_action is None and job_status == jobstatus.ACTIVATING_ENUM_INDEX) or \
(job_pending_action is None and job_status == jobstatus.RUNNING_ENUM_INDEX):
tracer.log_sandbox_pending_action_activate_detected(job_id, job_status, job_pending_action)
# check if the specified job is already running to prevent duplicate
if job_id in job_map:
continue
# create and start the new job
job_message_queue = Queue()
job_thread_exception_queue = Queue()
job = Job(self.sandbox_id, job_id, job_message_queue, self.jrds_client, job_thread_exception_queue)
job_map[job_id] = (job, job_message_queue, job_thread_exception_queue)
tracer.log_sandbox_started_tracking_job(job_id)
job.start()
elif job_pending_action == pendingactions.STOP_ENUM_INDEX:
tracer.log_sandbox_pending_action_stop_detected(job_id, job_status, job_pending_action)
# check if the specified job is already running before issuing pending action
if job_id not in job_map:
continue
# propagate pending action to job thread
job_map[job_id][1].put(job_pending_action)
elif job_pending_action is None:
tracer.log_sandbox_no_pending_action_detected(job_id, job_status)
else:
tracer.log_sandbox_unsupported_pending_action_detected(job_id, job_status, job_pending_action)
示例2: routine
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
def routine(self):
# clean up finished jobs
self.stop_tracking_terminated_jobs()
# get job actions
try:
job_actions = self.jrds_client.get_job_actions(self.sandbox_id)
except JrdsSandboxTerminated:
tracer.log_debug_trace("Terminating sandbox.")
global routine_loop
routine_loop = False
return
for job_action in job_actions:
job_id = job_action["JobId"]
job_data = self.jrds_client.get_job_data(job_id)
job_pending_action = job_data["pendingAction"]
job_status = job_data["jobStatus"]
# issue pending action
if job_pending_action == pendingactions.ACTIVATE_ENUM_INDEX or \
(job_pending_action is None and job_status == jobstatus.ACTIVATING_ENUM_INDEX) or \
(job_pending_action is None and job_status == jobstatus.RUNNING_ENUM_INDEX):
# check if the specified job is already running to prevent duplicate
if job_id in job_map:
continue
# create and start the new job
job_message_queue = Queue()
job_thread_exception_queue = Queue()
job = Job(self.sandbox_id, job_id, job_message_queue, self.jrds_client, job_thread_exception_queue)
job_map[job_id] = (job, job_message_queue, job_thread_exception_queue)
job.start()
tracer.log_debug_trace("Pending action activate detected.[pendingaction=" +
str(job_status) + "]")
elif job_pending_action == pendingactions.STOP_ENUM_INDEX:
# check if the specified job is already running before issuing pending action
if job_id not in job_map:
continue
# propagate pending action to job thread
job_map[job_id][1].put(job_pending_action)
tracer.log_debug_trace("Pending action detected")
elif job_pending_action is None:
tracer.log_debug_trace("No pending action detected")
else:
tracer.log_debug_trace("Unsupported pending action / job action")
示例3: get_status
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
def get_status(self):
client = foursquare.Foursquare(config.foursquare_client_id, client_secret=config.foursquare_client_secret)
all_plazas = client.venues.search(params={'near':'New York City', 'limit':50, 'intent':'browse', 'radius':5000, 'categoryId':'4bf58dd8d48988d164941735'} )
queue = Queue.Queue()
for i in range(3):
t = Job(queue)
t.setDaemon(True)
t.start()
ids = []
for v in all_plazas['venues']:
ids.append(v['id'])
queue.put(v['id'])
queue.join()
return "done"
"""
"""
return 'ok'
示例4: create_job
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
def create_job(self, name, config, running=False, port=5000):
"""
Stores information about job in the job dictionary.
If running is true then starts the job.
"""
module = self._get_plugin_with_name(name)
job_uuid = str(uuid.uuid4())
job_api_key = str(uuid.uuid4())
# TODO: Try/Catch if run does not exist
job = Job(
job_uuid,
name,
config,
job_api_key,
entry_point_group_name=self.plugin_manager.entry_point_group_name,
port=port,
)
logger.debug("Creating Job:{0} UUID:{1}".format(name, job_uuid))
self.jobs[job.uuid] = job
if running:
job.start()
return job
示例5: generate
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
def generate(self):
if self.filenamein != None and self.filenameout != None:
# Read all the information
jobs = {}
attempts = []
nodes = {}
power = []
maxpower = 0.0
for line in self.filein.readlines():
if line.startswith('Job'):
ret = self.getDict(line.split(' ')[1:-1])
jobId = ret['JOBID']
if jobId not in jobs:
jobs[jobId] = Job(jobId=jobId)
jobs[jobId].status = ret['JOB_STATUS']
jobs[jobId].submit = int(ret['SUBMIT_TIME'])
jobs[jobId].start = int(ret['START_TIME'])
jobs[jobId].finish = int(ret['FINISH_TIME'])
'''
job.nmapsapprox = 0
job.nredsapprox = 0
for attempt in attempts:
if job.jobId == attempt.getJobId():
if attempt.isMap():
job.nmaps += 1
if attempt.approx or attempt.status == Job.Status.DROPPED:
job.nmapsapprox += 1
if attempt.isMap():
job.nreds += 1
if attempt.approx or attempt.status == Job.Status.DROPPED:
job.nredsapprox += 1
job.quality = 1.0 - (1.0*job.nmapsapprox/job.nmaps)
'''
elif line.startswith('Task'):
pass
elif line.startswith('MapAttempt') or line.startswith('ReduceAttempt'):
ret = self.getDict(line.split(' ')[1:-1])
attempt = Attempt()
attempt.attemptId = ret['TASK_ATTEMPT_ID']
attempt.start = int(ret['START_TIME'])
attempt.finish = int(ret['FINISH_TIME'])
attempt.approx = (ret['APPROXIMATED'] == 'True' or ret['APPROXIMATED'] == 'true')
attempt.status = ret['TASK_STATUS']
attempt.nodeId = ret['HOSTNAME']
attempts.append(attempt)
# Update job information
jobId = attempt.getJobId()
if jobId not in jobs:
jobs[jobId] = Job(jobId=jobId)
jobs[jobId].addAttempt(attempt)
elif line.startswith('Node'):
ret = self.getDict(line.split(' ')[1:-1])
nodeId = ret['HOSTNAME']
if nodeId not in nodes:
nodes[nodeId] = []
nodes[nodeId].append((int(ret['TIME']), ret['STATUS']))
elif line.startswith('Power'):
ret = self.getDict(line.split(' ')[1:-1])
power.append((int(ret['TIME']), float(ret['POWER'])))
maxpower = max(maxpower, float(ret['POWER']))
# Node -> Attempts
nodeAttempts = {}
totalAttemptsApprox = 0
totalAttemptsDropped = 0
totalAttemptsPrecise = 0
for attempt in attempts:
if attempt.approx:
totalAttemptsApprox += 1
if attempt.status == Job.Status.DROPPED:
totalAttemptsDropped += 1
if attempt.status != Job.Status.DROPPED and not attempt.approx:
totalAttemptsPrecise += 1
if attempt.nodeId not in nodeAttempts:
nodeAttempts[attempt.nodeId] = []
nodeAttempts[attempt.nodeId].append(attempt)
if 'None' in nodeAttempts:
del nodeAttempts['None']
totalJobTime = 0
totalJobRunTime = 0
totalQuality = 0.0
for jobId in jobs:
job = jobs[jobId]
totalJobTime += job.finish - job.submit
totalJobRunTime += job.finish - job.start
totalQuality += job.getQuality()
totalJobTime = totalJobTime/len(jobs)
totalJobRunTime = totalJobRunTime/len(jobs)
totalJobQuality = totalQuality/len(jobs)
# Power
power = sorted(power, key=itemgetter(0))
totalenergy = 0.0
for t, p in power:
totalenergy += p
totaltime = power[-1][0]
# Generate output HTML
self.fileout.write('<html>\n')
#.........这里部分代码省略.........
示例6: logger_init
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
broccoli.broccoli
~~~~~~~~~~~~~
This project aims to ease the computation of certain problems by introducing
tools parallelization and multiprocessing.
:copyright: 2015 Manuel Martins, see AUTHORS for more details
:license: Apache 2.0, see LICENSE for more details
"""
import argparse
from logger import initialize as logger_init
import json_parser
from job import Job
import logging
if __name__ == '__main__':
args_parser = argparse.ArgumentParser(
description='Main entry point for Broccoli Module. Usage: python -m broccoli -i <input.json>'
)
args_parser.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true',
required=False)
args_parser.add_argument('-i', '--input', help='input json file / string', action='store',
dest='input', required=True)
logging.info('Broccoli - Initializing...')
args = args_parser.parse_args()
json = json_parser.parse(args.input)
logger_init(json, args.verbose)
job = Job(json)
job.start()
示例7: Robot
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import start [as 别名]
class Robot(object):
"""
The bridge class of the Robot.
Receives the request from the Front and
passes the command to the Back End (our_create).
Contributor: Xiangqing Zhang, Matthew O'Brien and Tianyu Liu.
"""
def __init__(self, port="sim"):
self.connection = None
self.port = port
self.eliza = eliza()
self.job = None
self.robotEncryption = RobotEncryption(0)
self._send_bytecode_flag = False
self._receive_bytecode_flag = False
self._take_other_robot_flag = False
self._follow_other_robot_flag = False
self.__receive_bytecode_flag = False
self._sendIR = False
self._follow_line = False
self._forward_until_black_line = False
self._forward_until_bumps = False
self._encode_message = False
self._teleportspeed = [0, 0];
self._forward_until_ir_signal = -1;
self.ir_time = 0.1
def _job(self, function, args=None, kwargs=None, life_span=0):
"""
Schedules a job for the robot.
@Parameter function: The NAME of the function.
@Parameter args: Must be LIST type.
@Parameter kwargs: Must be DICTIONARY type.
@Parameter life_span: Terminate the job after the given seconds.
If life_span==0, It will run forever unless
1. being terminated by code like this:
self._job_clear()
OR 2. calling this function (_job) again.
E.g. _job(robot_go_forward, args=[robot, 10], kwargs={"seconds": 2})
where robot_go_forward is defined as:
def robot_go_forward(robot, speed, seconds=2): ...
Calling this function is doing the same thing as:
robot_go_forward(robot, 10, seconds=2)
E.g.2 Check self.go_forward_until_black_line
Contributor: Xiangqing Zhang
"""
if not self.connection: self.connect()
if self.job:
self._log("The robot connection is busy. Terminating the current process...", "_job", "WARNING")
self._job_clear()
self._log("The robot connection has been terminated successfully.", "SUCCESS")
self.job = None
self.job = Job(function, args=args, kwargs=kwargs)
self.job.start()
if life_span > 0:
t = Timer(life_span, lambda: self._job_clear())
t.start()
def _job_clear(self):
"""
Clears all jobs.
Contributor: Xiangqing Zhang
"""
if self.job:
Job.in_use = False
self.job = None
if self.connection: self.connection.stop()
def _log(self, message, method_name, level="DEBUG", logger=None):
"""
Method that calls the logger to log events.
@Parameter message: A STR which is the content of the event to log.
@Parameter method_name: The name of the method where the event happens.
@Parameter level: Should be "DEBUG", "WARNING", "SEVERE", "INFO" and "SUCCESS".
@Parameter logger: Optional. By default, all loggers will be called to log the event.
E.g.1 self._log("Lost connection.", "disconnect", "DEBUG")
E.g.2 self._log("This will only be shown on the console.",
"test_function", logger="ConsoleLogger")
Contributor: Xiangqing Zhang
"""
robotLogger.add(message, method_name, level, logger)
def connect(self):
"""
Connects the our_create module.
Contributor: Tianyu Liu
"""
if not self.connection:
try:
self._log("Establishing the connection...", "_job")
self.connection = our_create.Create(self.port)
self._log("Connection established.", "_job", "SUCCESS")
except Exception as e:
self._log("Error occured while connecting: %s" % e, "connect")
def disconnect(self):
"""
Detach from the our_create module.
Contributor: Tianyu Liu
"""
#.........这里部分代码省略.........