def test_transaction_retries(): """Transactions can be retried if they fail.""" g = Group() for i in range(4): g.apply_async(retryable_transaction) g.join() names = select_names().flat eq_(names[-4:], ['a3', 'a4', 'a5', 'a6'])
def reset_update_server(self, server_name): from gevent.pool import Group group = Group() def local(): import dns.resolver return dns.resolver.query(server_name, 'TXT').response def recursive(): import dns.resolver from settings import NAME_SERVER ns = dns.resolver.query(NAME_SERVER, 'NS').response.answer[0] ns = ns.items[0].target.to_text() import socket ns = socket.gethostbyname(ns) import dns.message import dns.query q = dns.message.make_query(server_name, 'TXT') return dns.query.udp(q, ns) def public(ns): def _public(): import dns.message import dns.query q = dns.message.make_query(server_name, 'TXT') return dns.query.udp(q, ns) return _public workers = [ group.apply_async(i) for i in [ local, recursive, public('119.29.29.29'), public('114.114.114.114'), public('8.8.8.8'), ] ] for result in gevent.iwait(workers, 10): if result.successful(): result = result.value break else: log.exception(result.exception) else: group.kill() return False group.kill() result = result.answer[0] url = result.items[0].strings[0] self.set_update_url(url) return True
def reset_update_server(self, server_name): from gevent.pool import Group group = Group() def local(): import dns.resolver return dns.resolver.query(server_name, 'TXT').response def recursive(): import dns.resolver from settings import NAME_SERVER ns = dns.resolver.query(NAME_SERVER, 'NS').response.answer[0] ns = ns.items[0].target.to_text() import socket ns = socket.gethostbyname(ns) import dns.message import dns.query q = dns.message.make_query(server_name, 'TXT') return dns.query.udp(q, ns) def public(ns): def _public(): import dns.message import dns.query q = dns.message.make_query(server_name, 'TXT') return dns.query.udp(q, ns) return _public workers = [group.apply_async(i) for i in [ local, recursive, public('119.29.29.29'), public('114.114.114.114'), public('8.8.8.8'), ]] for result in gevent.iwait(workers, 10): if result.successful(): result = result.value break else: log.exception(result.exception) else: group.kill() return False group.kill() result = result.answer[0] url = result.items[0].strings[0] self.set_update_url(url) return True
with conn.cursor() as cur: cur.execute(cmd, p) conn.commit() except Exception as e: print(red(e, url)) # ltd = item['_id'] except Exception as e: if bad.find({'url': url}).count() <= 0: bad.save({'url': url}) print(red(e, url)) print(red('==> waiting for update...')) sleep(30) try: # to_mysql(nzol) # pool = Pool(4) # greenlets = [gevent.spawn(to_mysql, y) for y in nzol] # gevent.joinall(greenlets) # g = Group() # g.map_async(to_mysql, nbbs) # g.join() for x in xrange(4): g = Group() g.apply_async(to_mysql, args=(nzol,)) g.join() except Exception as e: print(11111) print(red(e))