SleepSort with concurrent.futures

A toy example that uses futures.

>>> def f(n):
...     print n, '->'
...     time.sleep(n)
...     print '<-', n
>>> with futures.ThreadPoolExecutor(max_workers=5) as ex:
...     ex.map(f, [1, 5, 2, 4, 3])
1 ->
5 ->
2 ->
4 ->
3 ->
<- 1
<- 2
<- 3
<- 4
<- 5

Leave a comment