Skip to content

Commit

Permalink
Convert example into a (smoke) doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Dec 14, 2024
1 parent 37f684e commit 9675290
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions datalad/support/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ class ProducerConsumer:
Examples
--------
A simple and somewhat boring example could be to count lines in '*.py'
files in parallel
from glob import glob
from pprint import pprint
from datalad.support.parallel import ProducerConsumer
def count_lines(fname):
with open(fname) as f:
return fname, len(f.readlines())
pprint(dict(ProducerConsumer(glob("*.py"), count_lines)))
A simple and somewhat boring example to count lines in '*.py'
>>> from glob import glob
>>> from pprint import pprint
>>> from datalad.support.parallel import ProducerConsumer
>>> def count_lines(fname):
... with open(fname) as f:
... return fname, len(f.readlines())
>>> pprint(dict(ProducerConsumer(glob("*.py"), count_lines))) # doctest: +SKIP
{'setup.py': 182, 'versioneer.py': 2136}
More usage examples could be found in `test_parallel.py` and around the
codebase `addurls.py`, `get.py`, `save.py`, etc.
Expand Down

0 comments on commit 9675290

Please sign in to comment.