def parallelize(self, c, numSlices=None):
        """
        Distribute a local Python collection to form an RDD. Using xrange
        is recommended if the input represents a range for performance.

        >>> sc.parallelize([0, 2, 3, 4, 6], 5).glom().collect()
        [[0], [2], [3], [4], [6]]
        >>> sc.parallelize(xrange(0, 6, 2), 5).glom().collect()
        [[], [0], [], [2], [4]]
        """
        numSlices = int(numSlices) if numSlices is not None else self.defaultParallelism
        if isinstance(c, xrange):
            size = len(c)
            if size == 0:
                return self.parallelize([], numSlices)
            step = c[1] - c[0] if size > 1 else 1
            start0 = c[0]

            def getStart(split):
                return start0 + int((split * size / numSlices)) * step

            def f(split, iterator):
                # it's an empty iterator here but we need this line for triggering the
                # logic of signal handling in FramedSerializer.load_stream, for instance,
                # SpecialLengths.END_OF_DATA_SECTION in _read_with_length. Since
                # FramedSerializer.load_stream produces a generator, the control should
                # at least be in that function once. Here we do it by explicitly converting
                # the empty iterator to a list, thus make sure worker reuse takes effect.
                # See more details in SPARK-26549.
                assert len(list(iterator)) == 0
                return xrange(getStart(split), getStart(split + 1), step)

            return self.parallelize([], numSlices).mapPartitionsWithIndex(f)

        # Make sure we distribute data evenly if it's smaller than self.batchSize
        if "__len__" not in dir(c):
            c = list(c)    # Make it a list so we can compute its length
        batchSize = max(1, min(len(c) // numSlices, self._batchSize or 1024))
        serializer = BatchedSerializer(self._unbatched_serializer, batchSize)

        def reader_func(temp_filename):
            return self._jvm.PythonRDD.readRDDFromFile(self._jsc, temp_filename, numSlices)

        def createRDDServer():
            return self._jvm.PythonParallelizeServer(self._jsc.sc(), numSlices)

        jrdd = self._serialize_to_jvm(c, serializer, reader_func, createRDDServer)
        return RDD(jrdd, self, serializer)
def parallelize ( self , c , numSlices = None ) : numSlices = int ( numSlices ) if numSlices is not None else self . defaultParallelism if isinstance ( c , xrange ) : size = len ( c ) if size == 0 : return self . parallelize ( [ ] , numSlices ) step = c [ 1 ] - c [ 0 ] if size > 1 else 1 start0 = c [ 0 ] def getStart ( split ) : return start0 + int ( ( split * size / numSlices ) ) * step def f ( split , iterator ) : assert len ( list ( iterator ) ) == 0 return xrange ( getStart ( split ) , getStart ( split + 1 ) , step ) return self . parallelize ( [ ] , numSlices ) . mapPartitionsWithIndex ( f ) if "__len__" not in dir ( c ) : c = list ( c ) batchSize = max ( 1 , min ( len ( c ) // numSlices , self . _batchSize or 1024 ) ) serializer = BatchedSerializer ( self . _unbatched_serializer , batchSize ) def reader_func ( temp_filename ) : return self . _jvm . PythonRDD . readRDDFromFile ( self . _jsc , temp_filename , numSlices ) def createRDDServer ( ) : return self . _jvm . PythonParallelizeServer ( self . _jsc . sc ( ) , numSlices ) jrdd = self . _serialize_to_jvm ( c , serializer , reader_func , createRDDServer ) return RDD ( jrdd , self , serializer )
Distribute a local Python collection to form an RDD. Using xrange
        is recommended if the input represents a range for performance.

        >>> sc.parallelize([0, 2, 3, 4, 6], 5).glom().collect()
        [[0], [2], [3], [4], [6]]
        >>> sc.parallelize(xrange(0, 6, 2), 5).glom().collect()
        [[], [0], [], [2], [4]]