Return a threadsafe counter function.
()
| 1490 | |
| 1491 | |
| 1492 | def counter() -> Callable[[], int]: |
| 1493 | """Return a threadsafe counter function.""" |
| 1494 | |
| 1495 | lock = threading.Lock() |
| 1496 | counter = itertools.count(1) |
| 1497 | |
| 1498 | # avoid the 2to3 "next" transformation... |
| 1499 | def _next(): |
| 1500 | with lock: |
| 1501 | return next(counter) |
| 1502 | |
| 1503 | return _next |
| 1504 | |
| 1505 | |
| 1506 | def duck_type_collection( |