def main(): real_addr = get_real_addr() if not real_addr: print('não foi possivel obter o ip real do utilizador.') exit() proxies = open('./input/proxies2.txt', 'r').read() routines = [] for proxy in proxies.splitlines(): host, port = proxy.split(':') routines.append({ 'function': check_proxy, 'args': { 'proxy_host': host, 'proxy_port': port, 'real_addr': real_addr, 'url_layer': 'http://presscomp.com.br/test/php/test.php', 'domain': 'https://www.netflix.com/', 'callback': on_proxy_check_finish } }) queue = Queue(routines, max_threads=300) queue.start()
def create_key_background(self, *args, **kwargs): try: kwargs["gpg"] = dumps(self) queue = Queue(queue_name="gpg_key_gen", unique_names=True) queue.push( name=u"".join([kwargs.get("name_real"), kwargs.get("name_comment"), kwargs.get("name_email")]), data=kwargs, ) return except QueuePushError: raise KeyGenerationError("A key with these same parameters is queued for creation")
def key_list(request, secret=True): msg_queue = Queue(queue_name='gpg_msg_queue') while True: msg_data = msg_queue.pull() if not msg_data: break; messages.add_message(request, msg_data.get('tag', messages.INFO), msg_data['message']) if secret: object_list = Key.get_all(gpg, secret=True, exclude=LocalNode().get().public_key) title = _(u'Private key list') else: object_list = Key.get_all(gpg) title = _(u'Public key list') return render_to_response('key_list.html', { 'object_list': object_list, 'title': title, }, context_instance=RequestContext(request))
def background_key_generator(): queue = Queue(queue_name='gpg_key_gen') kwargs = queue.pull() if kwargs: msg_queue = Queue(queue_name='gpg_msg_queue') try: gpg = loads(str(kwargs.pop('gpg'))) key = gpg.create_key(**kwargs) msg_queue.push( data={ 'tag': messages.SUCCESS, 'message': _(u'Key pair: %s, created successfully.') % key.fingerprint } ) except Exception, err_msg: msg_queue.push( data={ 'tag': messages.ERROR, 'message': _(u'Key creation error; %s') % err_msg } )
def setUp(self): self.passport = Task(20, "passport", "Bob") self.new_queue = Queue() self.passport1 = Task(30, "passport", "Bob 2") self.passport2 = Task(20, "passport", "Bob 3") self.passport3 = Task(20, "passport", "Bob 4")
class QueueManagerTests(unittest.TestCase): # setup testcase def setUp(self): self.passport = Task(20, "passport", "Bob") self.new_queue = Queue() self.passport1 = Task(30, "passport", "Bob 2") self.passport2 = Task(20, "passport", "Bob 3") self.passport3 = Task(20, "passport", "Bob 4") def test_create_task(self): self.assertTrue(isinstance(self.passport, Task)) # could this test be more elaborate? # TODO --> # For example # self.assertEquals(passport.time, 20) # self.assertEquals(passport.task_type, "passport") def test_create_queue(self): new_queue = Queue() self.assertTrue(isinstance(new_queue.startTime, float)) def test_add_to_queue(self): self.new_queue.add_to_queue(self.passport) self.assertTrue(self.passport in self.new_queue.tasks) def test_check_time_pass(self): new_queue = Queue() time.sleep(0.5) self.assertTrue(new_queue.startTime < time.time()) def test_estimate_queue_time(self): self.new_queue.add_to_queue(self.passport1) self.new_queue.add_to_queue(self.passport2) self.new_queue.add_to_queue(self.passport3) self.assertEqual(self.new_queue.estimate_time(), 70) def test_list_tasks(self): self.new_queue.add_to_queue(self.passport1) self.new_queue.add_to_queue(self.passport2) self.new_queue.add_to_queue(self.passport3) self.new_queue.list_tasks() def test_activate_task(self): self.new_queue.add_to_queue(self.passport1) self.new_queue.add_to_queue(self.passport2) self.new_queue.add_to_queue(self.passport3) self.new_queue.activate_task(self.passport1) self.assertEqual(self.new_queue.current_task, self.passport1)