本文整理汇总了Python中scheduler.Scheduler类的典型用法代码示例。如果您正苦于以下问题:Python Scheduler类的具体用法?Python Scheduler怎么用?Python Scheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Executor
class Executor(object):
def __init__(self, someprocess=None, logit=True, ticks=sys.maxint):
super(Executor,self).__init__()
if someprocess:
self.process = someprocess
else:
if ticks < sys.maxint:
ticks += 1
self.process = Scheduler(ticks=ticks, name="")
self.logit = logit
self.linker = Linker()
def schedule(self, components):
if type(components) is not list:
components = components['components']
self.process.send(('activate',components), 'control')
def kill(self, components):
if type(components) is not list:
components = components['components']
self.process.send(('deactivate',components), 'control')
def build(self, links):
self.graph = self.linker.link(links)
self.schedule(self.graph)
def run(self):
for _ in self.process.run():
if self.logit:
print utils.COLOR.cyan,
print "\tExecd: ", _,
print utils.COLOR.white
示例2: run_scheduler
def run_scheduler():
from scheduler import Scheduler
scheduler = Scheduler(taskdb=get_taskdb(), projectdb=get_projectdb(),
newtask_queue=newtask_queue, status_queue=status_queue, out_queue=scheduler2fetcher)
run_in_thread(scheduler.xmlrpc_run, port=scheduler_xmlrpc_port)
scheduler.run()
示例3: scheduler
def scheduler(ctx):
"""Run Scheduler."""
from fulmar.scheduler.projectdb import projectdb
from fulmar.message_queue import newtask_queue, ready_queue, cron_queue
from scheduler import Scheduler
scheduler = Scheduler(newtask_queue, ready_queue, cron_queue, projectdb)
scheduler.run()
示例4: nda_loop
def nda_loop():
ndutil.setTimezone()
ndlCom = NdlCom('nDroid-Executer', '127.0.0.1', 12322)
ndlCom.doCom('Initiating')
ndlCom.doCom('Loading Config')
cnfManager = CnfManager()
cnfManager.load('./nde.cnf')
cnfData = cnfManager.getCnfData()
nsQueue = Queue()
nsLock = threading.Lock()
netManager = NetManager()
netManager.setNdlCom(ndlCom)
netManager.setNsQueue(nsQueue, nsLock)
ndlCom.doCom('Starting Threads')
scheduler = Scheduler([ndlCom, nsQueue, nsLock], 'Scheduler')
scheduler.start()
reactor.listenUDP(cnfData['comPort'], netManager)
ndlCom.doCom('Listening Com Port')
reactor.run()
scheduler.join()
示例5: bootstrap_scheduler
def bootstrap_scheduler(self):
bootstrapped = False
try:
self.save("plugin_modules_library", self._plugin_modules_library)
Scheduler.clear_locks(self)
self.scheduler = Scheduler()
for plugin_info, fn, function_name in self.periodic_tasks:
meta = fn.will_fn_metadata
self.add_periodic_task(
plugin_info["full_module_name"],
plugin_info["name"],
function_name,
meta["sched_args"],
meta["sched_kwargs"],
meta["function_name"],
)
for plugin_info, fn, function_name in self.random_tasks:
meta = fn.will_fn_metadata
self.add_random_tasks(
plugin_info["full_module_name"],
plugin_info["name"],
function_name,
meta["start_hour"],
meta["end_hour"],
meta["day_of_week"],
meta["num_times_per_day"]
)
bootstrapped = True
except Exception, e:
self.startup_error("Error bootstrapping scheduler", e)
示例6: consumer_
def consumer_():
"""Consumer thread, tweets the book updates."""
con_schedule = Scheduler(config.TIMETABLE_TWI)
if config.BOT_TYPE == 'DesktopBot':
bot = DesktopBot()
bot.sign_in(auth.user, auth.password)
else:
bot = TwitterAPIBot()
bot.sign_in()
while True:
if con_schedule.is_time():
book = new_books.get()
total_len = len(book[0]) + len(book[1]) + 1
if total_len > 140:
book = (book[0][:-(total_len - 140)], book[1])
bot.tweet(book[0] + " " + book[1])
try:
print " [ [email protected]%s ] Tweet: %s" % (strftime("%H:%M:%S, %d/%m/%y"),
(book[0] + " " + book[1]))
except:
print " [ [email protected]%s ] Tweet." % strftime("%H:%M:%S, %d/%m/%y")
with to_mark_lock:
to_mark.append(book[1])
to_mark_lock.notify()
sleep(config.TW_FREQ)
else:
sleep(60)
示例7: bootstrap_scheduler
def bootstrap_scheduler(self):
print "Bootstrapping scheduler..."
bootstrapped = False
try:
self.save("plugin_modules_library", self._plugin_modules_library)
Scheduler.clear_locks(self)
self.scheduler = Scheduler()
for plugin_info, fn, function_name in self.periodic_tasks:
self.add_periodic_task(
plugin_info["full_module_name"],
plugin_info["name"],
function_name,
fn.sched_args,
fn.sched_kwargs,
fn.function_name,
)
for plugin_info, fn, function_name in self.random_tasks:
self.add_random_tasks(
plugin_info["full_module_name"],
plugin_info["name"],
function_name,
fn.start_hour,
fn.end_hour,
fn.day_of_week,
fn.num_times_per_day,
)
bootstrapped = True
except Exception, e:
self.startup_error("Error bootstrapping scheduler", e)
示例8: test_block
def test_block(self):
# Test that packets are not generated when the link is blocked.
scheduler = Scheduler()
system = SpiNNakerSystem(scheduler, 10)
link = DeadLink(scheduler)
# Uniform generator node
tg = SpiNNakerTrafficGenerator( scheduler
, system
, 1
, 0.1
, link
, link
)
tg.set_mesh_dimensions(100,100)
tg.set_mesh_position(50,50)
it = scheduler.run()
# Perform 1000 cycles
while it.next() < 2000 and tg.counters["generator_cycles"] < 1000:
pass
# Should have done 1000 cycles
self.assertEqual(tg.counters["generator_cycles"], 1000)
# We should have tried to send some number of packets that isn't all the
# time and not never (well, in theory we might not but hey, if this is going
# wrong you've got a bad day on your hands).
self.assertTrue(10 < tg.counters["generator_dropped_packets"] < 1000)
# None should have gone out
self.assertEqual(tg.counters["generator_injected_packets"], 0)
示例9: main
def main():
auth = Conf("bot.conf").getSection("auth")
if not "login" in auth or not "password" in auth:
print("Configuration not entirely filled.. Try again.")
sys.exit(1)
xmpp = Jarvis(auth["login"], auth["password"], auth["room"])
xmpp.ssl_version = ssl.PROTOCOL_SSLv3
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0199')
xmpp.register_plugin('xep_0085') # status message
xmpp.register_plugin('xep_0071') # Xhtml
xmpp.register_plugin('xep_0045') # multi user chan
xmpp.register_plugin('xep_0203') # XMPP Delayed messages
xmpp.register_plugin('xep_0249') # XMPP direct MUC invites
e = Events(xmpp)
e.start()
s = Scheduler(xmpp)
s.start()
t = ClientTask(xmpp)
t.start()
if xmpp.connect():
xmpp.process(block=True)
else:
print('Unable to connect')
示例10: save
def save(self, args):
if args["oldName"] == "":
key = args["name"]
av = Availability()
else:
key = args["oldName"]
av = Availability.find(self.env.get_db_cnx(), key)
av.name = args["name"]
av.validFrom = args["validFrom"]
av.validUntil = args["validUntil"]
av.resources = args["resources"]
av.weekdays = ""
self.appendWeekdays(av, args, "1")
self.appendWeekdays(av, args, "2")
self.appendWeekdays(av, args, "3")
self.appendWeekdays(av, args, "4")
self.appendWeekdays(av, args, "5")
self.appendWeekdays(av, args, "6")
self.appendWeekdays(av, args, "0")
av.workFrom = args["workFrom"]
av.workUntil = args["workUntil"]
av.save(self.env.get_db_cnx(), key)
scheduler = Scheduler()
scheduler.schedule(self.env, self.config);
return 'admin_availability.html', {"availabilities" : self.availabilities(), "view": "list"}
示例11: test_scheduler_bind_config
def test_scheduler_bind_config(self):
scheduler = Scheduler()
config = Config('''
timer test_timer {
interval: 2
event: test_timer_event
}
process demo_add {
trigger: op1_value, op2_value
script: {
sum := op1_value + op2_value
emit sum_value(sum)
}
}
process gen_op1 {
trigger: test_timer_event
script: {
emit op1_value(2)
}
}
process gen_op2 {
trigger: test_timer_event
script: {
emit op2_value(3)
}
}''')
scheduler.bind(config)
示例12: producer_
def producer_():
"""Producer thread, checks the book pages."""
pro_schedule = Scheduler(config.TIMETABLE_SCRA)
crawlers = []
for subcrawler in BookCrawler.__subclasses__():
crawlers.append(BookCrawler.factory(subcrawler.__name__))
while True:
if pro_schedule.is_time():
for crawler in crawlers:
books = crawler.get_books()
for book in books.keys():
if is_new_book(book):
# url of web page, book name, book url
insert_book(crawler.get_url(), books[book], book)
try:
print " [ [email protected]%s ] New book: %s" % (strftime("%H:%M:%S, %d/%m/%y"),
books[book] + \
" - " + \
crawler.get_url() + \
book)
except:
print " [ [email protected]%s ] New book." % strftime("%H:%M:%S, %d/%m/%y")
new_books.put((books[book], crawler.get_url() + book))
with to_mark_lock:
while not to_mark:
to_mark_lock.wait()
mark = to_mark.pop(0)
mark_tweeted(mark)
sleep(1)
# Wait
sleep(config.S_FREQ)
else:
sleep(60)
示例13: test_do_now
def test_do_now(self):
# If I schedule something now, it happens in the zeroth clock and then it
# exits
s = Scheduler()
s.do_now((lambda: None))
iterator = s.run()
self.assertEqual(iterator.next(), 0)
self.assertRaises(StopIteration, iterator.next)
示例14: SpiNNaker101Tests
class SpiNNaker101Tests(unittest.TestCase):
"""
Tests a chip in a very vague way...
"""
def setUp(self):
# Test that packets are generated appropriately when distributing with a
# uniform distribution.
self.scheduler = Scheduler()
self.system = SpiNNakerSystem(self.scheduler, 50000000)
self.chip = SpiNNaker101( self.scheduler
, self.system
, 4 # injection_buffer_length
, 10 # router_period
, 300000000
, 600000000
, 1 # core_period
, 1.0
, None
)
def test_loopback(self):
it = self.scheduler.run()
# Perform 1000 cycles
while it.next() < 4001:
pass
# Should have allowed all but 4 packets which are still in the queue
self.assertEqual(
self.chip.traffic_generator.counters["generator_injected_packets"] -
self.chip.traffic_generator.counters["generator_packets_received"],
4)
# Should have routed one packet per ten cycles...
self.assertEqual(self.chip.router.counters["packets_routed"], 400)
def test_external(self):
# Put the chip in a large mesh so stuff ends up there
self.chip.set_mesh_dimensions(1000,1000)
it = self.scheduler.run()
# Perform 1000 cycles
while it.next() < 4001:
pass
# Should have allowed very few packets through
self.assertTrue(
self.chip.traffic_generator.counters["generator_injected_packets"] < 10)
# The router should be very frustrated
self.assertTrue(self.chip.router.counters["router_blocked_cycles"] > 300)
示例15: test_silistix_link
def test_silistix_link(self):
s = Scheduler()
sl = SilistixLink(s, 10, 5)
# A simple packet container
class Packet(object):
def __init__(self,data,length):
self.data = data
self.length = length
# Initially can send
self.assertTrue(sl.can_send())
self.assertFalse(sl.can_receive())
sl.send(Packet(123,2))
# Can't send after sending something
self.assertFalse(sl.can_send())
self.assertFalse(sl.can_receive())
it = s.run()
# Can't send or recieve until send delay has elapsed
while it.next() != 10*2 + 5*1:
self.assertFalse(sl.can_send())
self.assertFalse(sl.can_receive())
# Can only recieve once data is stable
self.assertFalse(sl.can_send())
self.assertTrue(sl.can_receive())
# Can peek
self.assertEqual(sl.peek().data, 123)
self.assertFalse(sl.can_send())
self.assertTrue(sl.can_receive())
self.assertEqual(sl.peek().data, 123)
self.assertFalse(sl.can_send())
self.assertTrue(sl.can_receive())
# Recieved data is correct
self.assertEqual(sl.receive().data, 123)
# Can't recieve any more
self.assertFalse(sl.can_send())
self.assertFalse(sl.can_receive())
# Can't send or recieve until Acknowledge arrives
while it.next() != 10*2 + 5*2:
self.assertFalse(sl.can_send())
self.assertFalse(sl.can_receive())
# Can send once ack is back
self.assertTrue(sl.can_send())
self.assertFalse(sl.can_receive())
# Nothing else got scheduled...
self.assertRaises(StopIteration, it.next)