code: def init_nncontext(
      conf=None, spark_log_level="WARN", redirect_spark_log=True
  ):
      """
      Creates or gets a SparkContext with optimized configurations for BigDL performance.
      This method will also initialize the BigDL engine.
  
      Note: If you use spark-shell or Jupyter notebook, as the SparkContext is created
      before your code, you have to set the Spark configurations through command line options
      or the properties file before calling this method. In this case, you are recommended
      to use the launch scripts we provide:
      https://github.com/intel-analytics/analytics-zoo/tree/master/scripts.
  
      :param conf: An instance of SparkConf. If not specified, a new SparkConf with
             Analytics Zoo and BigDL configurations would be created and used.
             You can also input a string here to indicate the name of the application.
      :param spark_log_level: The log level for Spark. Default to be 'WARN'.
      :param redirect_spark_log: Whether to redirect the Spark log to local file. Default to be True.
  
      :return: An instance of SparkContext.
      """
      has_activate_sc = SparkContext._active_spark_context is not None
      # The following code copied and modified from
      # https://github.com/Valassis-Digital-Media/spylon-kernel/blob/master/
      # spylon_kernel/scala_interpreter.py
      if ZooContext.log_output and not has_activate_sc:
          import subprocess
          import pyspark.java_gateway
  
          spark_jvm_proc = None
  
          def Popen(*args, **kwargs):
              """Wraps subprocess.Popen to force stdout and stderr from the child process
              to pipe to this process without buffering.
              """
              nonlocal spark_jvm_proc
              # Override these in kwargs to avoid duplicate value errors
              # Set streams to unbuffered so that we read whatever bytes are available
              # when ready, https://docs.python.org/3.6/library/subprocess.html#popen-constructor
              kwargs["bufsize"] = 0
              # Capture everything from stdout for display in the notebook
              kwargs["stdout"] = subprocess.PIPE
              # Optionally capture stderr, otherwise it'll go to the kernel log
              kwargs["stderr"] = subprocess.PIPE
              spark_jvm_proc = subprocess.Popen(*args, **kwargs)
              return spark_jvm_proc
  
          pyspark.java_gateway.Popen = Popen
  
      if isinstance(conf, six.string_types):
          sc = getOrCreateSparkContext(conf=None, appName=conf)
      else:
          sc = getOrCreateSparkContext(conf=conf)
      sc.setLogLevel(spark_log_level)
  
      if (
          ZooContext.log_output
          and not has_activate_sc
          and spark_jvm_proc is not None
      ):
          if spark_jvm_proc.stdout is not None:
              stdout_reader = threading.Thread(
                  target=_read_stream,
                  daemon=True,
                  kwargs=dict(
                      fd=spark_jvm_proc.stdout, fn=sys.stdout.write
                  ),
              )
              stdout_reader.start()
          if spark_jvm_proc.stderr is not None:
              stderr_reader = threading.Thread(
                  target=_read_stream,
                  daemon=True,
                  kwargs=dict(
                      fd=spark_jvm_proc.stderr, fn=sys.stderr.write
                  ),
              )
              stderr_reader.start()
      check_version()
      if redirect_spark_log:
          redire_spark_logs()
          show_bigdl_info_logs()
      init_engine()
      set_python_home()
      return sc
  
imports: from bigdl.util.common import *
  from zoo.common.utils import callZooFunc
  from zoo.util.utils import set_python_home
  import warnings
  import multiprocessing
  import os
  import threading
  import sys
label_desc: Use image node_id 7 for calling a global function with example usage: init_nncontext(conf, spark_log_level, redirect_spark_log) and returns: sc, spark_jvm_proc