def test_task_assignment(self): # See https://github.com/surfly/gevent/blob/master/greentest/test__event.py INTERVAL = 2 self.scheduler.schedule('task_1', every_second(INTERVAL), func_1) assert self.scheduler.tasks[0].name == 'task_1' greenlet1, greenlet2 = self.scheduler.run(self.scheduler.tasks[0]) event1 = AsyncResult() greenlet1.link(event1) self.assertEqual(event1.get(), 100) assert greenlet2.ready() == False assert greenlet2.successful() == False sleep(INTERVAL) assert greenlet2.ready() == True assert greenlet2.successful() == True greenlet2.kill() greenlet1.kill() assert greenlet2.value[0].get() == 100, 'Actual %s' % str( greenlet2.value[0].get())
print("C**t spotted") rev = 0 if c**t[1] else 1 rev_string = "unprotected" if rev else "protected" stat = "User " + c**t[3] + " has moved account to " + rev_string print(stat) #rest.update_status(status=c**t[0]+' has '+ 'his/fer account') cur.execute('UPDATE C**T set IS_CUNT=? WHERE ID=?', (rev, c**t[0])) #for r in row: return def add_all(): for c**t in cunts: cur_cunt = rest.show_user(id=c**t) user_id = cur_cunt['id'] screen_name = cur_cunt['screen_name'] if cur_cunt['protected']: prot = 1 else: prot = 0 cur.execute( 'INSERT INTO C**T (IS_CUNT,USER_ID, SCREEN_NAME) VALUES (?,?,?)', (prot, user_id, screen_name)) #add_all() #who_is_a_cunt() scheduler = greenclock.Scheduler(logger_name='task_scheduler') scheduler.schedule('task_1', greenclock.every_second(4), who_is_a_cunt) scheduler.run_forever(start_at='once')
def test_builtin_timer_second(self): assert every_second(2).next().total_seconds() == 2 assert every_second(3600).next().total_seconds() == 3600
def add_task(self, name, task, tick=20): logger.debug("add task", task, 'name', name, 'tick', tick) self.scheduler.schedule(name, every_second(tick), task)
import greenclock from datetime import datetime import time def func_1(): print('Calling func_1() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_1() at ' + str(datetime.now())) def func_2(): print('Calling func_2() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_2() at ' + str(datetime.now())) def func_3(): print('Calling func_3() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_3() at ' + str(datetime.now())) if __name__ == "__main__": scheduler = greenclock.Scheduler(logger_name='task_scheduler') scheduler.schedule('task_1', greenclock.every_second(4), func_1) scheduler.schedule('task_2', greenclock.every_second(1), func_2) # Run at 41:00 every hour every day scheduler.schedule('task_3', greenclock.every_hour(minute=41, second=0), func_3) # Run task at 12:35:00 every day scheduler.schedule('task_2', greenclock.every_hour(hour=12, minute=35, second=0), func_2) # Starts the scheduling engine without delay scheduler.run_forever(start_at='once')
print('Calling func_1() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_1() at ' + str(datetime.now())) def func_2(): print('Calling func_2() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_2() at ' + str(datetime.now())) def func_3(): print('Calling func_3() at ' + str(datetime.now())) time.sleep(2) print('Ended call to func_3() at ' + str(datetime.now())) if __name__ == "__main__": scheduler = greenclock.Scheduler(logger_name='task_scheduler') scheduler.schedule('task_1', greenclock.every_second(4), func_1) scheduler.schedule('task_2', greenclock.every_second(1), func_2) # Run at 41:00 every hour every day scheduler.schedule('task_3', greenclock.every_hour(minute=41, second=0), func_3) # Run task at 12:35:00 every day scheduler.schedule('task_2', greenclock.every_hour(hour=12, minute=35, second=0), func_2) # Starts the scheduling engine without delay scheduler.run_forever(start_at='once')