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 @@ -975,36 +975,17 @@ which incur interpreter overhead.
975
975
""" Call a function repeatedly until an exception is raised.
976
976
977
977
Converts a call-until-exception interface to an iterator interface.
978
- Like builtins.iter(func, sentinel) but uses an exception instead
979
- of a sentinel to end the loop.
980
-
981
- Priority queue iterator:
982
- iter_except(functools.partial(heappop, h), IndexError)
983
-
984
- Non-blocking dictionary iterator:
985
- iter_except(d.popitem, KeyError)
986
-
987
- Non-blocking deque iterator:
988
- iter_except(d.popleft, IndexError)
989
-
990
- Non-blocking iterator over a producer Queue:
991
- iter_except(q.get_nowait, Queue.Empty)
992
-
993
- Non-blocking set iterator:
994
- iter_except(s.pop, KeyError)
995
-
996
978
"""
979
+ # iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
997
980
try:
998
981
if first is not None:
999
- # For database APIs needing an initial call to db.first()
1000
982
yield first()
1001
983
while True:
1002
984
yield func()
1003
985
except exception:
1004
986
pass
1005
987
1006
988
1007
-
1008
989
The following recipes have a more mathematical flavor:
1009
990
1010
991
.. testcode ::
You can’t perform that action at this time.
0 commit comments