Repository: spyder-ide/spyder

Issue:
PermissionError when trying to change current working directory
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Really, truly I have no idea why I am seeing these messages just now. 

### Traceback
```python-traceback
Exception in comms call get_cwd:
  File "/Users/EL-CAPITAN-2016/anaconda2/envs/spyder/lib/python3.8/site-packages/spyder_kernels/comms/commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(
  File "/Users/EL-CAPITAN-2016/anaconda2/envs/spyder/lib/python3.8/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](
  File "/Users/EL-CAPITAN-2016/anaconda2/envs/spyder/lib/python3.8/site-packages/spyder_kernels/console/kernel.py", line 332, in get_cwd
    return os.getcwd()
PermissionError: [Errno 1] Operation not permitted
```

## Versions

* Spyder version: 4.1.4 
* Python version: 3.8.1
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Darwin 19.4.0

### Dependencies

```

# Mandatory:
applaunchservices >=0.1.7      :  0.2.1 (OK)
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.5.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.16.1 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=1.0                   :  2.5.3 (OK)
pyls >=0.34.0;<1.0.0           :  0.34.1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.5 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.1.2 (OK)
spyder_kernels >=1.9.2;<1.10.0 :  1.9.2 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  19.0.1 (OK)

# Optional:
cython >=0.21                  :  None (OK)
matplotlib >=2.0.0             :  3.3.0 (OK)
numpy >=1.7                    :  1.19.1 (OK)
pandas >=0.13.1                :  1.1.1 (OK)
scipy >=0.17.0                 :  1.5.0 (OK)
sympy >=0.7.3                  :  None (OK)
```



Discussion:
Hi @cgeady, thanks for opening this. We will solve this bug for our next release.
@steff456, we need to catch this error on the kernel and pass. But please remember that spyder-kernels still support Python 2, you can't catch `PermissionError` but the exception class from which it inherits and it's also present in Python 2.

Resolving patch:
diff --git a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py
--- a/external-deps/spyder-kernels/spyder_kernels/console/kernel.py
+++ b/external-deps/spyder-kernels/spyder_kernels/console/kernel.py
@@ -469,7 +469,10 @@ def set_cwd(self, dirname):
 
     def get_cwd(self):
         """Get current working directory."""
-        return os.getcwd()
+        try:
+            return os.getcwd()
+        except (IOError, OSError):
+            pass
 
     def get_syspath(self):
         """Return sys.path contents."""


Test patch: