Return a threadsafe counter function.
()
| 1400 | |
| 1401 | |
| 1402 | def counter() -> Callable[[], int]: |
| 1403 | """Return a threadsafe counter function.""" |
| 1404 | |
| 1405 | lock = threading.Lock() |
| 1406 | counter = itertools.count(1) |
| 1407 | |
| 1408 | # avoid the 2to3 "next" transformation... |
| 1409 | def _next(): |
| 1410 | with lock: |
| 1411 | return next(counter) |
| 1412 | |
| 1413 | return _next |
| 1414 | |
| 1415 | |
| 1416 | def duck_type_collection( |