This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing.pool import ThreadPool | |
| import queue | |
| from typing import Any, Callable, Iterator | |
| def threadpool_imap(func: Callable[[Any], Any], | |
| iterable: Iterator[Any], | |
| *, | |
| num_thread: int = 4 | |
| ) -> Iterator[Any]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import queue | |
| from concurrent.futures import ThreadPoolExecutor | |
| from contextlib import contextmanager | |
| from typing import Any, Callable, Iterator | |
| @contextmanager | |
| def concurrent_imap(func: Callable[[Any], Any], | |
| iterable: Iterator[Any], | |
| *, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [2]: inv100 = stripe.Invoice.list(limit=100) | |
| In [8]: from itertools import islice | |
| In [9]: [(i, inv.id, inv.created) for i, inv in islice(enumerate(inv100.data), 20)] | |
| Out[9]: | |
| [(0, 'in_1EhxnEGObuJZja1rsNGjJcNe', 1559736000), | |
| (1, 'in_1EhxnFGObuJZja1rT295LqNl', 1559736000), | |
| (2, 'in_1EhxnFGObuJZja1r9xZutCpP', 1559736000), | |
| (3, 'in_1EhxnGGObuJZja1riY3HzPDl', 15597360 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [2]: pg1 = stripe.Invoice.list() | |
| In [3]: pg2 = stripe.Invoice.list(starting_after=pg1.data[-1].id) | |
| In [4]: pg2.data[0].id | |
| Out[4]: 'in_1EgJwwDhOpaK71Z9NO4eU8Jz' | |
| In [5]: invs100 = stripe.Invoice.list(limit=100) | |
| In [6]: [i.id for i in invs100].index(pg2.data[0].id) |