Skip to content

Python guard/wrapper for SparkContext from pyspark - allows you to use python `with` operator with SparkContext

License

Notifications You must be signed in to change notification settings

curusarn/spark-context-with

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

spark-context-with

Python guard/wrapper for SparkContext from pyspark.
Allows you to use python with operator with SparkContext.
Useful for throwing exceptions, prematurely exiting functions, etc.

Example

from sparkContextWith import SparkContextWith

myAwesomeFunction(sc, whatever):
  #NOTE: use sc exactly as regular SparkContext ... eg:
  data = sc.sequenceFile("path")
  #TODO: whatever you want
  #NOTE: it is safe to throw exceptions from here
  return true

sparkconf = SparkConf().setMaster("yarn-client").setAppName("My awesome app")

with SparkContextWith(sparkconf) as sc:
  myAwesomeFunction(sc, whatever)

#NOTE: no need to sc.stop() - SparkContextWith does that for you

About

Python guard/wrapper for SparkContext from pyspark - allows you to use python `with` operator with SparkContext

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages