# Buggy code
def comm_channel_manager(self, comm_id, queue_message=False):
    """Use comm_channel instead of shell_channel."""
    if queue_message:
        # Send without comm_channel
        yield
        return

    if not self.comm_channel_connected():
        # Ask again for comm config
        self.remote_call()._send_comm_config()
        timeout = 25
        self._wait(
            self.comm_channel_connected,
            self._sig_comm_port_changed,
            "Timeout while waiting for comm port.",
            timeout,
        )

    id_list = self.get_comm_id_list(comm_id)
    for comm_id in id_list:
        self._comms[comm_id]["comm"]._send_channel = self.kernel_client.comm_channel
    try:
        yield
    finally:
        for comm_id in id_list:
            self._comms[comm_id][
                "comm"
            ]._send_channel = self.kernel_client.shell_channel


# Traceback (TimeoutError)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/qtconsole/base_frontend_mixin.py", line 138, in _dispatch
handler(msg)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 172, in _handle_execute_reply
self.refresh_namespacebrowser()
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 63, in refresh_namespacebrowser
callback=self.set_namespace_view
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 538, in __call__
call_dict, call_data, self._comm_id)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 130, in _get_call_return_value
with self.comm_channel_manager(comm_id, queue_message=not interrupt):
File "/home/nerohmot/my-envs/s4/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 87, in comm_channel_manager
timeout)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 168, in _wait
raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for comm port.
Traceback (most recent call last):
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/qtconsole/base_frontend_mixin.py", line 138, in _dispatch
handler(msg)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 172, in _handle_execute_reply
self.refresh_namespacebrowser()
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 63, in refresh_namespacebrowser
callback=self.set_namespace_view
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 538, in __call__
call_dict, call_data, self._comm_id)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 130, in _get_call_return_value
with self.comm_channel_manager(comm_id, queue_message=not interrupt):
File "/home/nerohmot/my-envs/s4/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 87, in comm_channel_manager
timeout)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 168, in _wait
raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for comm port.
Traceback (most recent call last):
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/plugin.py", line 554, in set_current_client_working_directory
shellwidget.set_cwd(directory)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/shell.py", line 178, in set_cwd
self.call_kernel(interrupt=True).set_cwd(dirname)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 538, in __call__
call_dict, call_data, self._comm_id)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 130, in _get_call_return_value
with self.comm_channel_manager(comm_id, queue_message=not interrupt):
File "/home/nerohmot/my-envs/s4/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 87, in comm_channel_manager
timeout)
File "/home/nerohmot/my-envs/s4/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 168, in _wait
raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for comm port.

# Fixed code
def comm_channel_manager(self, comm_id, queue_message=False):
    """Use comm_channel instead of shell_channel."""
    if queue_message:
        # Send without comm_channel
        yield
        return

    if not self.comm_channel_connected():
        # Ask again for comm config
        self.remote_call()._send_comm_config()
        raise CommError("Comm not connected.")

    id_list = self.get_comm_id_list(comm_id)
    for comm_id in id_list:
        self._comms[comm_id]["comm"]._send_channel = self.kernel_client.comm_channel
    try:
        yield
    finally:
        for comm_id in id_list:
            self._comms[comm_id][
                "comm"
            ]._send_channel = self.kernel_client.shell_channel