Skip to content

Commit 1789cd4

Browse files
committed
f in foreach could be generator or not.
1 parent 2871b80 commit 1789cd4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

python/pyspark/rdd.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,14 @@ def foreachPartition(self, f):
655655
>>> def f(iterator):
656656
... for x in iterator:
657657
... print x
658-
... yield None
659658
>>> sc.parallelize([1, 2, 3, 4, 5]).foreachPartition(f)
660659
"""
661660
def func(it):
662-
f(it)
663-
return iter([])
661+
r = f(it)
662+
try:
663+
return iter(r)
664+
except TypeError:
665+
return iter([])
664666
self.mapPartitions(func).count() # Force evaluation
665667

666668
def collect(self):

0 commit comments

Comments
 (0)