Differences creating tuples and collections.namedtuples

alex23 wuwei23 at gmail.com
Tue Feb 19 02:47:50 CET 2013


On Feb 18, 9:47 pm, John Reid <johnbaronr... at gmail.com> wrote:
> See http://article.gmane.org/gmane.comp.python.ipython.user/10270 for more info.

One quick workaround would be to use a tuple where required and then
coerce it back to Result when needed as such:

def sleep(secs):
    import os, time, parallel_helper
    start = time.time()
    time.sleep(secs)
    return tuple(parallel_helper.Result(os.getpid(), time.time() -
start))

rc = parallel.Client()
v = rc.load_balanced_view()
async_result = v.map_async(sleep, range(3, 0, -1), ordered=False)
for ar in async_result:
    print parallel_helper.Result(*ar)

You can of course skip the creation of Result in sleep and only turn
it into one in the display loop, but it all depends on additional
requirements (and adds some clarity to what is happening, I think).



More information about the Python-list mailing list