spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Problem with copy the Variable with sys.stdout #13473

Open pipetrunks opened 4 years ago

pipetrunks commented 4 years ago

Description

What steps will reproduce the problem?

import sys

Temp = sys.stdout

I try to copy the variable "Temp"

Traceback

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1037, in copy
    obj = self.delegate.get_value(idx)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1386, in get_value
    return self.parent().get_value(name)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1439, in get_value
    value = self.shellwidget.get_value(name)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\namespacebrowser.py", line 99, in get_value
    timeout=CALL_KERNEL_TIMEOUT).get_value(name)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 542, in __call__
    call_dict, call_data, self._comm_id)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 114, in _get_call_return_value
    call_dict, call_data, comm_id)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 420, in _get_call_return_value
    return self._sync_error(reply['value'])
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 480, in _sync_error
    error_wrapper.raise_error()
  File "C:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 376, in _set_call_return_value
    comm_id=self.calling_comm_id)

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

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

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 437, in dump
    self.save(obj)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 662, in save_reduce
    save(state)

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 885, in _batch_setitems
    save(v)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 662, in save_reduce
    save(state)

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 885, in _batch_setitems
    save(v)

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 885, in _batch_setitems
    save(v)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 662, in save_reduce
    save(state)

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 885, in _batch_setitems
    save(v)

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

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 885, in _batch_setitems
    save(v)

  File "C:\ProgramData\Anaconda3\lib\pickle.py", line 524, in save
    rv = reduce(self.proto)

  File "stringsource", line 2, in zmq.backend.cython.context.Context.__reduce_cython__

TypeError: no default __reduce__ due to non-trivial __cinit__

Versions

Dependencies

atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.12.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
sphinx >=0.6.6               :  2.4.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.15 (OK)
matplotlib >=2.0.0           :  3.1.3 (OK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  1.0.1 (OK)
scipy >=0.17.0               :  1.4.1 (OK)
sympy >=0.7.3                :  1.5.1 (OK)
steff456 commented 4 years ago

Hi @pipetrunks,

I could reproduce this error as well, thanks for reporting we will work in this for our next release in a couple of months

steff456 commented 4 years ago

@impact27 can you please help us with this one?

impact27 commented 4 years ago

We should just add a try except and pass on any error. Should we inform the user that spyder can’t copy this variable? I am not sure what the expected behaviour would be there

steff456 commented 4 years ago

I think that we need @ccordoba12 opinion. What I'm wondering is there's a way to actually copy that variable or it is extremely difficult?

impact27 commented 4 years ago

Well there is not really a value to be copied. I am not sure what “copy” means in this context.

steff456 commented 4 years ago

Yes, I think you are right and in this case the stdout is a stream and not a String so I think it we can pass the error and inform the user that Spyder is not able to copy this variable

ccordoba12 commented 4 years ago

Great advice @steff456! I also agree with that solution.