Repository: spyder-ide/spyder

Issue:
Issue reporter due to disconnected network drive after wakeup
## Description

### What steps will reproduce the problem?

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

1. Open file in Spyder that is located on network drive
2. sleep PC
3. wake up

My Windows (7) disconnects the network drives at 2., or 3. and reconnects automatically after wakeup. As long as I don't interact with Spyder, there shouldn't be an issue, but as of version 4.0 Spyder prompts for opening an issue. Can this be prevented?

### Traceback
```python-traceback
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\api.py", line 146, in run
    self.queue_events(self.timeout)
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\read_directory_changes.py", line 75, in queue_events
    winapi_events = read_events(self._handle, self.watch.is_recursive)
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\winapi.py", line 346, in read_events
    buf, nbytes = read_directory_changes(handle, recursive)
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\winapi.py", line 306, in read_directory_changes
    raise e
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\winapi.py", line 302, in read_directory_changes
    ctypes.byref(nbytes), None, None)
  File "C:\Users\w012029\AppData\Local\Continuum\miniconda3\envs\wms\lib\site-packages\watchdog\observers\winapi.py", line 107, in _errcheck_bool
    raise ctypes.WinError()
OSError: [WinError 64] Der angegebene Netzwerkname ist nicht mehr verfügbar.

```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.6.8
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 7

### Dependencies

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.10.1 (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.7.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.2 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
sphinx >=0.6.6               :  2.1.2 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.14 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.16.4 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
sympy >=0.7.3                :  None (NOK)
```



Discussion:
@andfoy, please take a look at this one. I think it shouldn't be hard to catch and pass on this error.

Resolving patch:
diff --git a/spyder/plugins/projects/utils/watcher.py b/spyder/plugins/projects/utils/watcher.py
--- a/spyder/plugins/projects/utils/watcher.py
+++ b/spyder/plugins/projects/utils/watcher.py
@@ -13,6 +13,7 @@
 from qtpy.QtCore import QObject, Signal
 from qtpy.QtWidgets import QMessageBox
 
+import watchdog
 from watchdog.observers import Observer
 from watchdog.events import FileSystemEventHandler
 
@@ -23,6 +24,32 @@
 logger = logging.getLogger(__name__)
 
 
+class BaseThreadWrapper(watchdog.utils.BaseThread):
+    """
+    Wrapper around watchdog BaseThread class.
+    This is necessary for issue spyder-ide/spyder#11370
+    """
+    queue = None
+
+    def __init__(self):
+        super(BaseThreadWrapper, self).__init__()
+        self._original_run = self.run
+        self.run = self.run_wrapper
+
+    def run_wrapper(self):
+        try:
+            self._original_run()
+        except OSError as e:
+            logger.exception('Watchdog thread exited with error %s',
+                             e.strerror)
+            self.queue.put(e)
+
+
+# Monkeypatching BaseThread to prevent the error reported in
+# spyder-ide/spyder#11370
+watchdog.utils.BaseThread = BaseThreadWrapper
+
+
 class WorkspaceEventHandler(QObject, FileSystemEventHandler):
     """
     Event handler for watchdog notifications.


Test patch: