File tree Expand file tree Collapse file tree 1 file changed +1
-20
lines changed Expand file tree Collapse file tree 1 file changed +1
-20
lines changed Original file line number Diff line number Diff line change @@ -983,36 +983,17 @@ which incur interpreter overhead.
983
983
""" Call a function repeatedly until an exception is raised.
984
984
985
985
Converts a call-until-exception interface to an iterator interface.
986
- Like builtins.iter(func, sentinel) but uses an exception instead
987
- of a sentinel to end the loop.
988
-
989
- Priority queue iterator:
990
- iter_except(functools.partial(heappop, h), IndexError)
991
-
992
- Non-blocking dictionary iterator:
993
- iter_except(d.popitem, KeyError)
994
-
995
- Non-blocking deque iterator:
996
- iter_except(d.popleft, IndexError)
997
-
998
- Non-blocking iterator over a producer Queue:
999
- iter_except(q.get_nowait, Queue.Empty)
1000
-
1001
- Non-blocking set iterator:
1002
- iter_except(s.pop, KeyError)
1003
-
1004
986
"""
987
+ # iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
1005
988
try:
1006
989
if first is not None:
1007
- # For database APIs needing an initial call to db.first()
1008
990
yield first()
1009
991
while True:
1010
992
yield func()
1011
993
except exception:
1012
994
pass
1013
995
1014
996
1015
-
1016
997
The following recipes have a more mathematical flavor:
1017
998
1018
999
.. testcode ::
You can’t perform that action at this time.
0 commit comments