Python:从Gevent Greenlet获得价值

我正在学习Gevent,但无法获得greenlet中调用函数返回的值.以下代码

import gevent.monkey
gevent.monkey.patch_socket()

import gevent
from gevent import Greenlet

import urllib2
import simplejson as json

def fetch(pid):
    response = urllib2.urlopen('http://time.jsontest.com')
    result = response.read()
    json_result = json.loads(result)
    datetime = json_result['time']

    print('Process %s: %s' % (pid,datetime))
    return json_result['time']

def synchronous():
    for i in range(1,10):
        fetch(i)

def asynchronous():
    threads = [Greenlet.spawn(fetch,i) for i in range(10)]
    result = gevent.joinall(threads)
    print [Greenlet.value(thread) for thread in threads]

print('Synchronous:')
synchronous()

print('Asynchronous:')
asynchronous()

给我错误

print [Greenlet.value(thread) for thread in threads]
AttributeError: type object 'Greenlet' has no attribute 'value'

我做错了什么,如何从每个greenlet中获取价值?

最佳答案
根据你想要的http://www.gevent.org/intro.html

def asynchronous():
    threads = [Greenlet.spawn(fetch,i) for i in range(10)]
    result = gevent.joinall(threads)
    print [thread.value for thread in threads]

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...