Re:Python 3.6 – Asynchronous Comprehensions
by lars512 on Sunday December 11, 2016 @03:09AM
(#13150111)
Parallel map is built in to Python already with pools.
import requests
import multiprocessing as mp
pool = mp.Pool()
urls = ["http://httpbin.org/get?a=#{}".format(i) for i in range(100)]
pool.map(requests.get, urls)
Re:Python 3.6 – Asynchronous Comprehensions
by noobermin on Saturday December 10, 2016 @11:32PM
(#13149604)
As a non-rubyist, this took me a minute to guess through. I prefer list comps.
hint: I'm implying familiarity over elegance.
Re:Python 3.6 – Asynchronous Comprehensions
by dorianm on Sunday December 11, 2016 @12:35AM
(#13149763)
I guess in Python it would be going from:
list(map(lambda x: x**2, [1, 2, 3, 4]))
To: list(pmap(lambda x: x**2, [1, 2, 3, 4]))
Re:Python 3.6 – Asynchronous Comprehensions
by noobermin on Sunday December 11, 2016 @12:44AM
(#13149783)
Right, and neither of those are pythonic. There is no need for a lambda when you have comprehensions.
This comment may relate better to your point: I would personally prefer "afor" over "async for", FWIW. One thing I don't feel "async for" is being more explicit over being more verbose. The symmetry with "await foo" is broken though.
e.g.: Replace:
To: From 17.55s to 0.72s.