Repository: spyder-ide/spyder

Issue:
RuntimeError when closing project
## Description

### What steps will reproduce the problem?

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

I developed “🌿Cotton Plant Disease Prediction & Get Cure App” using Artificial Intelligence especially Deep learning. As Farmer, I know Farmer can’t solve Farm’s complex and even small problems due to lack of perfect education. So as AI enthusiastic I decided to solve this problem using the latest technology like AI.

### Traceback
```python-traceback
  File "C:\Users\Idrees\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 2238, in valid_project
    self.projects.close_project()
  File "C:\Users\Idrees\anaconda3\lib\site-packages\spyder\plugins\projects\plugin.py", line 364, in close_project
    self.watcher.stop()
  File "C:\Users\Idrees\anaconda3\lib\site-packages\spyder\plugins\projects\utils\watcher.py", line 158, in stop
    self.observer.join()
  File "C:\Users\Idrees\anaconda3\lib\threading.py", line 1006, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started
```

## Versions

* Spyder version: 4.1.4 
* Python version: 3.8.3
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```

# Mandatory:
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)
paramiko >=2.4.0               :  2.7.1 (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                  :  0.29.21 (OK)
matplotlib >=2.0.0             :  3.2.2 (OK)
numpy >=1.7                    :  1.18.5 (OK)
pandas >=0.13.1                :  1.0.5 (OK)
scipy >=0.17.0                 :  1.5.0 (OK)
sympy >=0.7.3                  :  1.6.1 (OK)
```



Discussion:
Hey @Midrees330, thanks for reporting and nice to know you're using Spyder to develop AI models for cotton plant disease prediction.

We'll fix this error in our next version (4.2.0), to be released next week.

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
@@ -154,6 +154,12 @@ def start(self, workspace_folder):
 
     def stop(self):
         if self.observer is not None:
-            self.observer.stop()
-            self.observer.join()
-            del self.observer
+            # This is required to avoid showing an error when closing
+            # projects.
+            # Fixes spyder-ide/spyder#14107
+            try:
+                self.observer.stop()
+                self.observer.join()
+                del self.observer
+            except RuntimeError:
+                pass


Test patch: