# Buggy code
def get_value(self, name):
    """Ask kernel for a value"""
    reason_big = _("The variable is too big to be retrieved")
    reason_not_picklable = _("The variable is not picklable")
    msg = _(
        "%s.<br><br>"
        "Note: Please don't report this problem on Github, "
        "there's nothing to do about it."
    )
    try:
        return self.call_kernel(
            interrupt=True, blocking=True, timeout=CALL_KERNEL_TIMEOUT
        ).get_value(name)
    except TimeoutError:
        raise ValueError(msg % reason_big)
    except UnpicklingError:
        raise ValueError(msg % reason_not_picklable)


# Traceback (_pickle.PicklingError)
File "C:\Anaconda\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1037, in copy
obj = self.delegate.get_value(idx)
File "C:\Anaconda\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1386, in get_value
return self.parent().get_value(name)
File "C:\Anaconda\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1439, in get_value
value = self.shellwidget.get_value(name)
File "C:\Anaconda\lib\site-packages\spyder\plugins\ipythonconsole\widgets\namespacebrowser.py", line 99, in get_value
timeout=CALL_KERNEL_TIMEOUT).get_value(name)
File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "C:\Anaconda\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call get_value:

File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 343, in _handle_remote_call
self._set_call_return_value(msg_dict, return_value)

File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 376, in _set_call_return_value
comm_id=self.calling_comm_id)

File "C:\Anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 245, in _send_message
data, protocol=self._comms[comm_id]['pickle_protocol'])]

File "C:\Anaconda\lib\site-packages\cloudpickle\cloudpickle.py", line 1125, in dumps
cp.dump(obj)

File "C:\Anaconda\lib\site-packages\cloudpickle\cloudpickle.py", line 482, in dump
return Pickler.dump(self, obj)

File "C:\Anaconda\lib\pickle.py", line 409, in dump
self.save(obj)

File "C:\Anaconda\lib\pickle.py", line 476, in save
f(self, obj) # Call unbound method with explicit self

File "C:\Anaconda\lib\site-packages\cloudpickle\cloudpickle.py", line 1010, in save_file
raise pickle.PicklingError("Cannot pickle closed files")

_pickle.PicklingError: Cannot pickle closed files

# Fixed code
def get_value(self, name):
    """Ask kernel for a value"""
    reason_big = _("The variable is too big to be retrieved")
    reason_not_picklable = _("The variable is not picklable")
    msg = _(
        "%s.<br><br>"
        "Note: Please don't report this problem on Github, "
        "there's nothing to do about it."
    )
    try:
        return self.call_kernel(
            interrupt=True, blocking=True, timeout=CALL_KERNEL_TIMEOUT
        ).get_value(name)
    except TimeoutError:
        raise ValueError(msg % reason_big)
    except (PicklingError, UnpicklingError):
        raise ValueError(msg % reason_not_picklable)