Github user davies commented on a diff in the pull request: https://github.com/apache/spark/pull/16263#discussion_r92833679 --- Diff: python/pyspark/rdd.py --- @@ -2349,7 +2352,12 @@ def toLocalIterator(self): """ with SCCallSiteSync(self.context) as css: port = self.ctx._jvm.PythonRDD.toLocalIteratorAndServe(self._jrdd.rdd()) - return _load_from_socket(port, self._jrdd_deserializer) + # We set a timeout for connecting socket. The connection only begins when we start + # to consume the first element. If we do not begin to consume the returned iterator + # immediately, there will be a failure. + iter = _load_from_socket(port, self._jrdd_deserializer) --- End diff -- I think we could have a wrapper to load items, and return the iterator in _load_from_socket(): ``` def _load_from_socket(port): ... return serializer.load_stream(sock.makefile("rb", 65536)) ``` The `finally` may be optional, GC cloud close the socket (should be confirmed).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org