Exemple #1
0
pool = evy.GreenPool()

def fetch_title (url):
    d = feedparser.parse(url)
    return d.feed.get('title', '')


def app (environ, start_response):
    if environ['REQUEST_METHOD'] != 'POST':
        start_response('403 Forbidden', [])
        return []

    # the pile collects the result of a concurrent operation -- in this case,
    # the collection of feed titles
    pile = evy.GreenPile(pool)
    for line in environ['wsgi.input'].readlines():
        url = line.strip()
        if url:
            pile.spawn(fetch_title, url)
        # since the pile is an iterator over the results,
    # you can use it in all sorts of great Pythonic ways
    titles = '\n'.join(pile)
    start_response('200 OK', [('Content-type', 'text/plain')])
    return [titles]


if __name__ == '__main__':
    from evy import wsgi

    wsgi.server(evy.listen(('localhost', 9010)), app)
if __name__ == "__main__":
    usage = 'usage: websocket_chat -p pub address -s sub address port number'
    if len(sys.argv) != 6:
        print usage
        sys.exit(1)

    pub_addr = sys.argv[2]
    sub_addr = sys.argv[4]
    try:
        port = int(sys.argv[5])
    except ValueError:
        print "Error port supplied couldn't be converted to int\n", usage
        sys.exit(1)

    try:
        pub_socket = ctx.socket(zmq.PUB)
        pub_socket.connect(pub_addr)
        print "Publishing to %s" % pub_addr
        sub_socket = ctx.socket(zmq.SUB)
        sub_socket.connect(sub_addr)
        sub_socket.setsockopt(zmq.SUBSCRIBE, "")
        print "Subscribing to %s" % sub_addr
    except:
        print "Couldn't create sockets\n", usage
        sys.exit(1)

    spawn_n(subscribe_and_distribute, sub_socket)
    listener = evy.listen(('127.0.0.1', port))
    print "\nVisit http://localhost:%s/ in your websocket-capable browser.\n" % port
    wsgi.server(listener, dispatch)
Exemple #3
0

def fetch_title(url):
    d = feedparser.parse(url)
    return d.feed.get('title', '')


def app(environ, start_response):
    if environ['REQUEST_METHOD'] != 'POST':
        start_response('403 Forbidden', [])
        return []

    # the pile collects the result of a concurrent operation -- in this case,
    # the collection of feed titles
    pile = evy.GreenPile(pool)
    for line in environ['wsgi.input'].readlines():
        url = line.strip()
        if url:
            pile.spawn(fetch_title, url)
        # since the pile is an iterator over the results,
    # you can use it in all sorts of great Pythonic ways
    titles = '\n'.join(pile)
    start_response('200 OK', [('Content-type', 'text/plain')])
    return [titles]


if __name__ == '__main__':
    from evy import wsgi

    wsgi.server(evy.listen(('localhost', 9010)), app)
if __name__ == "__main__":
    usage = 'usage: websocket_chat -p pub address -s sub address port number'
    if len(sys.argv) != 6:
        print usage
        sys.exit(1)

    pub_addr = sys.argv[2]
    sub_addr = sys.argv[4]
    try:
        port = int(sys.argv[5])
    except ValueError:
        print "Error port supplied couldn't be converted to int\n", usage
        sys.exit(1)

    try:
        pub_socket = ctx.socket(zmq.PUB)
        pub_socket.connect(pub_addr)
        print "Publishing to %s" % pub_addr
        sub_socket = ctx.socket(zmq.SUB)
        sub_socket.connect(sub_addr)
        sub_socket.setsockopt(zmq.SUBSCRIBE, "")
        print "Subscribing to %s" % sub_addr
    except:
        print "Couldn't create sockets\n", usage
        sys.exit(1)

    spawn_n(subscribe_and_distribute, sub_socket)
    listener = evy.listen(('127.0.0.1', port))
    print "\nVisit http://localhost:%s/ in your websocket-capable browser.\n" % port
    wsgi.server(listener, dispatch)