Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion how to fetch my own url in tornado?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
yition cheung  
View profile  
 More options Oct 9 2012, 10:09 pm
From: yition cheung <zyx3998...@gmail.com>
Date: Tue, 9 Oct 2012 19:09:40 -0700 (PDT)
Local: Tues, Oct 9 2012 10:09 pm
Subject: how to fetch my own url in tornado?

Some of my handlers are used to return json, I write a new handler to get
the jsons and comput them to generate new json, but i can't do this, it
seems to no effect. But when i fetch them in a alone python script, it runs
well. Cos i use gevent and urlopen? but I don't know how to do this use
tornado's method. Please help.

some code:
def fetch_info(url, n):
    fetch_url = str(url) + str(n)
    raw_info = urlopen(fetch_url).read()
    info = tornado.escape.json_decode(raw_info)
    return info

def getinfo(n):
    url = 'http://localhost:8888/serverdemic/'
    info_dict = fetch_info(url, n)
    down_speed = info_dict['net_info']['load']
    up_speed = info_dict['net_info']['up']
    return (down_speed, up_speed)

def getstatus():
    servers = [i['machineNo'] for i in db.nebula_machine.find()]
    jobs = [gevent.spawn(fetch_info, 'http://127.0.0.1:8888/serverstatus/',
i) for i in servers]
    gevent.joinall(jobs)
    ids = [job.value['id'] for job in jobs if job.value['status'] != 0]
    return ids

class TotalNetHandler(BaseHandler):
    def get(self):
        jobs = [gevent.spawn(getinfo, i) for i in getstatus()]
        gevent.joinall(jobs)
        raw_info = [job.value for job in jobs]
        down_up = zip(*raw_info)
        downup_sum = [sum(i) for i in down_up]
        info = {'down': downup_sum[0], 'up': downup_sum[1]}
        self.write(tornado.escape.json_encode(info))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.