本文整理汇总了Python中dispatcher.Dispatcher.start方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.start方法的具体用法?Python Dispatcher.start怎么用?Python Dispatcher.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.start方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stage
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
class Stage():
"""
A stage is a segment in a pipeline defining the type of workers it employs.
"""
def __init__(self, name, WorkerClass, num_workers, in_buffer,
out_buffer, seq_number, pipeline, path):
self.name = name
self.WorkerClass = WorkerClass
self.num_workers = num_workers
self.pipeline = pipeline
self.input = in_buffer
self.output = out_buffer
self.seq_number = seq_number
self.worker_environ = dict(pool=self, path=path)
self.isactive = False
self.progress = 0
def _create_worker(self, num):
return [ self.WorkerClass(self.input, self.output, i, **self.worker_environ) for i in range(num) ]
def add_worker(self):
new_worker = self._create_worker(1)
self.workers.append(new_worker)
self.num_workers += 1
def remove_worker(self):
self.workers.pop().join()
self.num_woker -= 1
def start(self):
# Global activity flag
self.isactive = True
# Dispatcher-controlled Event worker threads wait for before they start
self.wakeSignal = threading.Event()
# create worker threads
self.workers = self._create_worker(self.num_workers)
# create dispatcher thread
self.dispatcher = Dispatcher(self)
# start threads
[worker.start() for worker in self.workers]
# start dispatcher thread
self.dispatcher.start()
def stop(self):
"""
Block until all workers have finished current job. Input queue does not
have to be empty.
"""
self.isactive = False
self.dispatcher.join()
def join(self):
"""
Block until the input queue is empty.
"""
self.input.join()
self.isactive = False
self.dispatcher.join()
示例2: start_flask
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def start_flask():
global job_queue
global dispatcher
# Create IN job queue & job dispatcher
job_queue = Queue()
#d = Dispatcher(job_queue=job_queue, log_queue=loggingqueue.queue) Process based logging
dispatcher = Dispatcher(job_queue=job_queue)
dispatcher.start()
app.run(debug=True, use_reloader=False)
示例3: start
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def start():
global dispatcher
if dispatcher.isAlive():
logging.warning("Cannot start dispatcher : Dispatcher is already running")
return "Cannot start dispatcher : Dispatcher is already running"
else:
dispatcher = Dispatcher(job_queue=job_queue)
dispatcher.start()
return "Dispatcher started... %s" % dispatcher
示例4: main_loop_parallel
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def main_loop_parallel():
color_stdout("Started {0}\n".format(" ".join(sys.argv)), schema='tr_text')
jobs = lib.Options().args.jobs
if jobs < 1:
# faster result I got was with 2 * cpu_count
jobs = 2 * multiprocessing.cpu_count()
if jobs > 0:
color_stdout("Running in parallel with %d workers\n\n" % jobs,
schema='tr_text')
randomize = True
task_groups = lib.worker.get_task_groups()
if lib.Options().args.reproduce:
task_groups = lib.worker.reproduce_task_groups(task_groups)
jobs = 1
randomize = False
dispatcher = Dispatcher(task_groups, jobs, randomize)
dispatcher.start()
lib.worker.print_greetings()
color_stdout("\n", '=' * 86, "\n", schema='separator')
color_stdout("WORKR".ljust(6), schema='t_name')
color_stdout("TEST".ljust(48), schema='t_name')
color_stdout("PARAMS".ljust(16), schema='test_var')
color_stdout("RESULT\n", schema='test_pass')
color_stdout('-' * 81, "\n", schema='separator')
try:
is_force = lib.Options().args.is_force
dispatcher.wait()
dispatcher.wait_processes()
color_stdout('-' * 81, "\n", schema='separator')
has_failed = dispatcher.statistics.print_statistics()
has_undone = dispatcher.report_undone(verbose=True)
if has_failed:
return EXIT_FAILED_TEST
if has_undone:
return EXIT_NOTDONE_TEST
except KeyboardInterrupt:
color_stdout('-' * 81, "\n", schema='separator')
dispatcher.statistics.print_statistics()
dispatcher.report_undone(verbose=False)
raise
except HangError:
color_stdout('-' * 81, "\n", schema='separator')
dispatcher.statistics.print_statistics()
dispatcher.report_undone(verbose=True)
return EXIT_HANG
return EXIT_SUCCESS
示例5: __init__
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
class IA:
def __init__(self, name, **kargs):
# Initialisation du logger
self.logger = getLogger("ia")
f=open(name+".ini")
fileConfig(f)
f.close()
self.logger.info("Starting %s robot" % name)
assert(name in ["petit", "gros"])
module = __import__("robots."+name)
self.robot = getattr(getattr(module, name), name.capitalize()+"Robot")()
Robot.copy_from(self.robot)
# On crase les attributs du robot par ceux passs ici en argument, utiles pour le testing
for argument in kargs:
setattr(self.robot, argument, kargs[argument])
self.can_sock = socket.socket()
self.ui_sock = socket.socket()
self.inter = socket.socket()
self.logger.debug("Trying to connect to the CAN")
self.can_sock.connect((self.robot.can_ip, self.robot.can_port))
self.logger.debug("Trying to connect to the UI")
self.ui_sock.connect((self.robot.ui_ip, self.robot.ui_port))
self.logger.debug("Trying to connect to the INTERCOMM")
self.inter.connect((self.robot.inter_ip, self.robot.inter_port))
self.can = Can(self.can_sock)
self.ui = UI(self.ui_sock)
self.inter = InterCom(self.inter)
self.dispatcher = Dispatcher(self.robot, self.can, self.ui)
self.can.dispatcher = self.dispatcher
self.ui.dispatcher = self.dispatcher
self.inter.dispatcher = self.dispatcher
self.dispatcher.start() # Mieux si demarre avant can et ui
self.can.start()
self.ui.start()
self.inter.start()
self.logger.info("IA initialized")
self.ui.join()
self.logger.info("IA stopped")
示例6: main
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def main():
tasksq = multiprocessing.Queue()
mgr = multiprocessing.Manager()
e = mgr.Event()
scheduler = Scheduler(e, tasksq) # Reads the probs to be executed and queues in tasksq
dispatcher = Dispatcher(tasksq)
o = Oscillator(e, 1) # TODO: this should be a configuration
o.start()
scheduler.start()
dispatcher.start()
o.join()
scheduler.join()
示例7: __init__
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
class IA:
def __init__(self, name, **kargs):
self.logger = getLogger("ia")
module = __import__("robots."+name) # import robots.<name>
self.robot = getattr(getattr(module, name), name.capitalize()+"Robot")() # create <Name>Robot
self.comm = Comm(self.robot)
self.dispatcher = Dispatcher(self.robot, self.comm)
self.dispatcher.start()
self.logger.info("IA started !")
from events.internal import InternalEvent
event = InternalEvent("start")
self.dispatcher.add_event(event)
示例8: StartDispatcher
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def StartDispatcher():
#with daemon.DaemonContext():
# try:
if True:
if True:
dispatcher = Dispatcher(
address='localhost',
exchange='barkingowl',
self_dispatch=False,
DEBUG=True
)
url = {
#'target_url': "http://timduffy.me/",
'target_url': "http://henrietta.org/",
'doc_types': [
#'application/pdf',
'*',
],
#'title': "TimDuffy.Me",
'title': 'Town of Henrietta, NY',
#'description': "Tim Duffy's Personal Website",
'description': "Town of Henrietta, NY Website.",
#'max_link_level': 1,
'max_link_level': 1,
'creation_datetime': str(datetime.datetime.now()),
'allowed_domains': [
],
'sleep_time': 0, # 1 secon
}
urls = []
urls.append(url)
print "Seting URLs ..."
dispatcher.set_urls(urls)
print "Done."
# note: blocking
print "Starting dispatcher ..."
dispatcher.start()
print "Done."
示例9: dispatch
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def dispatch(resultfiles):
"""
Create dispatch semaphore and threads.
Join threads and returns dispatch status.
"""
threads = []
semaphore = threading.BoundedSemaphore(value=Configuration.semaphore)
for result in resultfiles:
expectfile = os.path.join(Configuration.expecteddir, result)
resultfile = os.path.join(Configuration.resultdir, result)
t = Dispatcher(result, expectfile, resultfile, result, semaphore)
t.start()
threads.append(t)
for t in threads:
t.join()
return(Dispatcher.get_pass(), Dispatcher.get_total())
示例10: EmonHub
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import start [as 别名]
def EmonHub():
# Load settings
settings = ConfigObj("emonhub.conf", file_error=True)
# Create queue for node packets
queue = Queue.Queue(0)
# Create and start serial listener
a = Listener(queue,settings)
a.start()
# Create and start http dispatcher
b = Dispatcher(queue,settings)
b.start()
while 1:
try:
time.sleep(0.1)
except KeyboardInterrupt:
print "Stopping threads"
a.stop = True
b.stop = True
break