Repository: spyder-ide/spyder

Issue:
Spyder stalls for 2 minutes on startup when starting a remote Xorg session
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When Starting Spyder 3.3.6 on Python 3.7.3 via SSH from cygwin, startup pauses for 120 seconds, then completes successfully.  This pause doesn't happen when starting spyder via ssh under Python 2.7, nor under Python 3.7.3 with local x-server.


### What steps reproduce the problem?

1. ssh -X from cygwin to linux machine
2. start spyder with from command line under python 3.7

### What is the expected output? What do you see instead?

Expect startup to complete within a few seconds (as happens using Python 2.7 to start spyder), but instead it pauses for 2 minutes during startup.

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->
With SPYDER_DEBUG set to 3:
```
$ spyder
Start of MainWindow constructor
End of MainWindow constructor
*** Start of MainWindow setup ***
  ..core actions
  ..toolbars
  ..tools
  ..sift?
  ..plugin: internal console
```
Pauses for 2 minutes here, then continues...
```
    ..internal console: initializing
  ..plugin: working directory
```



## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.3.6
* Python version: 3.7.3
* Qt version: 5.9.7
* PyQt version: 1.8.0
* Operating System name/version: Ubuntu 18.10 / Windows 10 (build 18362) + cygwin (XWin V1.20.4.0)

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
IPython >=4.0     :  7.6.1 (OK)
cython >=0.21     :  0.29.12 (OK)
jedi >=0.9.0      :  0.13.3 (OK)
matplotlib >=2.0.0:  3.1.0 (OK)
nbconvert >=4.0   :  5.5.0 (OK)
numpy >=1.7       :  1.16.4 (OK)
pandas >=0.13.1   :  0.24.2 (OK)
psutil >=0.3      :  5.6.3 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pyflakes >=0.6.0  :  2.1.1 (OK)
pygments >=2.0    :  2.4.2 (OK)
pylint >=0.25     :  2.3.1 (OK)
qtconsole >=4.2.0 :  4.5.1 (OK)
rope >=0.9.4      :  0.14.0 (OK)
sphinx >=0.6.6    :  2.1.2 (OK)
sympy >=0.7.3     :  1.4 (OK)
```



Discussion:
> When Starting Spyder 3.3.6 on Python 3.7.3 via SSH from cygwin

Sorry, we don't support cygwin nor use it, so we can't offer any help about this. Besides, no one else has reported an error like this before.
Found the issue---it's in the spyder.widgets.github.backend widget.  Commenting it out from reporterror.py fixes the startup delay.  The 'import keyring' line seems to be the culprit, which blocks if called from inside an SSH session (and takes 2 minutes to timeout).  Issue has nothing to do with cygwin---starting spyder via 'ssh -X localhost' on the linux machine is enough to replicate.
Ok, thanks for finding the issue. How do you think we could fix this? 
Looks like maybe the 'import keyring' is stalling waiting for a response from dbus, which is failing when connecting over SSH.  I don't immediately see a way of detecting the failure without waiting 2 minutes, so maybe a quick workaround would be to detect that spyder is being launched from an ssh session ("SSH_CONNECTION" in os.environ) and if so, print a warning to the user and disable the import of spyder.widgets.github.backend widget in reporterror.py
> a quick workaround would be to detect that spyder is being launched from an ssh session ("SSH_CONNECTION" in os.environ)

That's nice, I didn't know about that env var, thanks! I think we're going to deactivate using `keyring` in that situation.

We're using `keyring` to allow users saving their GH credentials safely to not enter them every time they want to report a bug. But you just proved us that it can't be used all the time.

Resolving patch:
diff --git a/spyder/widgets/github/backend.py b/spyder/widgets/github/backend.py
--- a/spyder/widgets/github/backend.py
+++ b/spyder/widgets/github/backend.py
@@ -15,11 +15,14 @@
 """
 
 import logging
+import os
 import sys
 import webbrowser
 
 try:
-    import keyring
+    # See: spyder-ide/spyder#10221
+    if os.environ.get('SSH_CONNECTION') is None:
+        import keyring
 except Exception:
     pass
 


Test patch: