# Buggy code
def launch_process(self, cmd, **kw):
    pass


# Traceback (KeyError)
[D 2017-07-26 12:02:29.586 KernelGatewayApp] Instantiating kernel 'Spark 2.1 - Scala (YARN Cluster Mode)' with process proxy: kernel_gateway.services.kernels.processproxy.YarnProcessProxy
[I 170726 12:02:29 base:37] Request http://elyra-fyi-node-1:8088//ws/v1/cluster/nodes
[E 2017-07-26 12:02:29.591 KernelGatewayApp] Unhandled error in API request
Traceback (most recent call last):
File "/opt/anaconda2/lib/python2.7/site-packages/notebook/base/handlers.py", line 521, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/notebook/services/kernels/handlers.py", line 49, in post
kernel_id = yield gen.maybe_future(km.start_kernel(kernel_name=model['name']))
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/remotemanager.py", line 24, in start_kernel
kernel_id = yield gen.maybe_future(super(RemoteMappingKernelManager, self).start_kernel(*args, **kwargs))
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/manager.py", line 81, in start_kernel
kernel_id = yield gen.maybe_future(super(SeedingMappingKernelManager, self).start_kernel(*args, **kwargs))
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/opt/anaconda2/lib/python2.7/site-packages/tornado/gen.py", line 307, in wrapper
yielded = next(result)
File "/opt/anaconda2/lib/python2.7/site-packages/notebook/services/kernels/kernelmanager.py", line 123, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/opt/anaconda2/lib/python2.7/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/remotemanager.py", line 91, in start_kernel
self.process_proxy = process_proxy_class(self, self.kernel_spec.process_proxy_connection_file_mode, **kw)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/processproxy.py", line 570, in __init__
super(YarnProcessProxy, self).__init__(kernel_manager, connection_file_mode, **kw)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/processproxy.py", line 283, in __init__
super(RemoteProcessProxy, self).__init__(kernel_manager, connection_file_mode, **kw)
File "/opt/anaconda2/lib/python2.7/site-packages/kernel_gateway/services/kernels/processproxy.py", line 69, in __init__
env_dict = kw['env']
KeyError: 'env'

# Fixed code
def launch_process(self, cmd, **kw):
    env_dict = kw.get("env")
    if env_dict is None:
        env_dict = dict(os.environ.copy())
        kw.update({"env": env_dict})

    # see if KERNEL_LAUNCH_TIMEOUT was included from user
    self.kernel_launch_timeout = float(
        env_dict.get("KERNEL_LAUNCH_TIMEOUT", elyra_kernel_launch_timeout)
    )

    # add the applicable kernel_id to the env dict
    env_dict["KERNEL_ID"] = self.kernel_id
    for k in env_pop_list:
        env_dict.pop(k, None)
    self.log.debug("BaseProcessProxy.launch_process() env: {}".format(kw.get("env")))