Otherwise, launch_gateway builds the command to start spark-submit:
Finds SPARK_HOME with ./bin/spark-submit
Appends all the configuration properties (from the input conf) using --conf
Appends PYSPARK_SUBMIT_ARGS environment variable if defined or assumes pyspark-shell
launch_gateway sets up _PYSPARK_DRIVER_CONN_INFO_PATH environment variable to point at an unique temporary file.
launch_gateway configures a pipe to stdin for the corresponding Java gateway process to use to monitor the Python process.
launch_gateway starts bin/spark-submit command and waits for a connection info file to be created at _PYSPARK_DRIVER_CONN_INFO_PATH. launch_gateway reads the port and the secret from the file once available.
launch_gateway connects to the gateway using py4j's ClientServer or JavaGateway based on PYSPARK_PIN_THREAD environment variable.
launch_gateway imports Spark packages and classes (using py4j):