Python多处理池get / join方法停止执行

时间:2015-08-02 18:17:03

标签: python multiprocessing freeze

我正在尝试从python多处理库中的池对象中执行不同的方法。我尝试了太多方法,但是当我调用任何方法.get()或.join()时,它们都会卡住。我已经google了很多,没有任何主题和教程对我有用。我的代码是下一个:

def get_profile(artist_id):
    buckets = ['years_active', 'genre', 'images']
    artist = Artist(artist_id)
    return artist.get_profile(buckets=buckets)

def get_songs(artist_id):
    from echonest.playlist import Playlist
    return Playlist().static(artist_ids=[artist_id])

def get_similar(artist_id):
    artist = Artist(artist_id)
    return artist.get_similar(min_familiarity=0.5, buckets=['images'])


def get_news(artist_id):
    artist = Artist(artist_id)
    print "Executing get_news"
    return artist.get_news(high_relevance='true')


def search_artist(request, artist_name, artist_id):
    from multiprocessing import Pool, Process

    requests = [
        dict(func=get_profile, args=(artist_id,)),
        dict(func=get_songs, args=(artist_id,)),
        dict(func=get_similar, args=(artist_id,)),
        dict(func=get_news, args=(artist_id,))
    ]

    pool = Pool(processes=2)

    for req in requests:
        result = pool.apply_async(req['func'], req['args'])
    pool.close()
    pool.join()
    print "HERE IT STOPS AND NOTHING HAPPENS."
    output = [p.get() for p in results]

希望有人可以提供帮助,因为我已经坚持这么久了。提前谢谢。

0 个答案:

没有答案