This is a working example running on wsgi,
import os import sys
Path for spark source folder
s.environ['SPARK_HOME'] = "C:\Apache\spark-1.4.1"
Append pyspark to Python Path
ys.path.append("C:\Apache\spark-1.4.1\python")
from pyspark import SparkContext from pyspark import SparkConf from pyspark.sql import SQLContext
This is our application object. It could have any name,
except when using mod_wsgi where it must be "application" def application(environ, start_response):
# Initialize SparkContext
sc = SparkContext('local')
words = sc.parallelize(["scala","java","hadoop","spark","akka"])
count = words.count()
#print count
sc.stop()
response_body = "Successfully imported Spark Modules and the total words are: " + str(count)
# HTTP response code and message
status = '200 OK'
# These are HTTP headers expected by the client.
# They must be wrapped as a list of tupled pairs:
# [(Header name, Header value)].
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]
# Send them to the server using the supplied function
start_response(status, response_headers)
# Return the response body.
# Notice it is wrapped in a list although it could be any iterable.
return [response_body]</pre>