# Buggy code
def argv(self):
    """Command to start kernels"""
    # Python interpreter used to start kernels
    if CONF.get("main_interpreter", "default"):
        pyexec = get_python_executable()
    else:
        # Avoid IPython adding the virtualenv on which Spyder is running
        # to the kernel sys.path
        os.environ.pop("VIRTUAL_ENV", None)
        pyexec = CONF.get("main_interpreter", "executable")
        if not is_python_interpreter(pyexec):
            pyexec = get_python_executable()
            CONF.set("main_interpreter", "executable", "")
            CONF.set("main_interpreter", "default", True)
            CONF.set("main_interpreter", "custom", False)

    # Part of spyder-ide/spyder#11819
    is_different = is_different_interpreter(pyexec)

    # Fixes spyder-ide/spyder#3427.
    if os.name == "nt":
        dir_pyexec = osp.dirname(pyexec)
        pyexec_w = osp.join(dir_pyexec, "pythonw.exe")
        if osp.isfile(pyexec_w):
            pyexec = pyexec_w

    # Command used to start kernels
    if is_different and is_conda_env(pyexec=pyexec):
        # If this is a conda environment we need to call an intermediate
        # activation script to correctly activate the spyder-kernel

        # If changes are needed on this section make sure you also update
        # the activation scripts at spyder/plugins/ipythonconsole/scripts/
        kernel_cmd = [
            get_activation_script(),  # This is bundled with Spyder
            get_conda_activation_script(),
            get_conda_env_path(pyexec),  # Might be external
            pyexec,
            "{connection_file}",
        ]
    else:
        kernel_cmd = [pyexec, "-m", "spyder_kernels.console", "-f", "{connection_file}"]
    logger.info("Kernel command: {}".format(kernel_cmd))

    return kernel_cmd


# Traceback (ProcessLookupError)
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\_pswindows.py", line 707, in wrapper
return fun(self, *args, **kwargs)
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\_pswindows.py", line 954, in create_time
return cext.proc_create_time(self.pid)
ProcessLookupError: [Errno 3] No such process

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\__init__.py", line 474, in _init
self.create_time()
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\__init__.py", line 824, in create_time
self._create_time = self._proc.create_time()
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\_pswindows.py", line 709, in wrapper
raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=16124)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\zhour\Anaconda3\lib\site-packages\qtconsole\manager.py", line 27, in poll
super(QtKernelRestarter, self).poll()
File "C:\Users\zhour\Anaconda3\lib\site-packages\jupyter_client\restarter.py", line 113, in poll
self.kernel_manager.restart_kernel(now=True, newports=newports)
File "C:\Users\zhour\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 361, in restart_kernel
self.shutdown_kernel(now=now, restart=True)
File "C:\Users\zhour\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 321, in shutdown_kernel
self._kill_kernel()
File "C:\Users\zhour\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\utils\manager.py", line 78, in _kill_kernel
self.kill_proc_tree(self.kernel.pid)
File "C:\Users\zhour\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\utils\manager.py", line 44, in kill_proc_tree
parent = psutil.Process(pid)
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\__init__.py", line 447, in __init__
self._init(pid)
File "C:\Users\zhour\Anaconda3\lib\site-packages\psutil\__init__.py", line 487, in _init
raise NoSuchProcess(pid, None, msg)
psutil.NoSuchProcess: psutil.NoSuchProcess no process found with pid 16124
WARNING:traitlets:kernel died: 18.000895500183105
WARNING:traitlets:kernel died: 18.000853061676025
WARNING:traitlets:kernel died: 18.000853538513184
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853061676025
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853061676025
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000852823257446
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853300094604
WARNING:traitlets:kernel died: 18.000853061676025

# Fixed code
def argv(self):
    """Command to start kernels"""
    # Python interpreter used to start kernels
    if CONF.get("main_interpreter", "default"):
        pyexec = get_python_executable()
    else:
        # Avoid IPython adding the virtualenv on which Spyder is running
        # to the kernel sys.path
        os.environ.pop("VIRTUAL_ENV", None)
        pyexec = CONF.get("main_interpreter", "executable")
        if not is_python_interpreter(pyexec):
            pyexec = get_python_executable()
            CONF.set("main_interpreter", "executable", "")
            CONF.set("main_interpreter", "default", True)
            CONF.set("main_interpreter", "custom", False)

    # Part of spyder-ide/spyder#11819
    is_different = is_different_interpreter(pyexec)

    # Command used to start kernels
    if is_different and is_conda_env(pyexec=pyexec):
        # If this is a conda environment we need to call an intermediate
        # activation script to correctly activate the spyder-kernel

        # If changes are needed on this section make sure you also update
        # the activation scripts at spyder/plugins/ipythonconsole/scripts/
        kernel_cmd = [
            get_activation_script(),  # This is bundled with Spyder
            get_conda_activation_script(),
            get_conda_env_path(pyexec),  # Might be external
            pyexec,
            "{connection_file}",
        ]
    else:
        kernel_cmd = [pyexec, "-m", "spyder_kernels.console", "-f", "{connection_file}"]
    logger.info("Kernel command: {}".format(kernel_cmd))

    return kernel_cmd