Open
Description
I have a pyspark script as follow :
pi.py
import sys
from random import random
from operator import add
from pyspark import SparkContext
if name == "main":
""" Usage: pi [partitions]
"""
sc = SparkContext(appName="PythonPi")
partitions = int(sys.argv[1]) if len(sys.argv) > 1 else 2
n = 100000 * partitions
def f(_):
x = random() * 2 - 1
y = random() * 2 - 1
return 1 if x ** 2 + y ** 2 < 1 else 0
count = sc.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
print("Pi is roughly %f" % (4.0 * count / n))
sc.stop()
we usual use this way to execute script : spark-submit pi.py
But i can't use the command :coverage run spark-submit pi.py;