Repository: spyder-ide/spyder

Issue:
Spyder 3 opens a command prompt window when running certain commands
I updated to Spyder 3, and now every time I click Run to launch my theano code, it will open nvcc.exe in a separate Windows command prompt window. Nothing else has changed. 

**What steps will reproduce the problem?**
1.  Run some code that uses nvcc.exe (or probably any other compiler) in Spyder 2
2.  Update to Spyder 3
3.  repeating step 1 (exactly the same code) will cause a black command prompt windows to appear (launch of compiler.exe)

**What is the expected output? What do you see instead?**
I expect to see no external applications opened in separate command prompt windows
## Versions and main components
- Spyder Version: 3.0.0
- Python Version: 2.7.11
- Operating system: Windows 10 Anniversary Edition
- Cuda 7.5
- Theano 0.9 dev2
## Dependencies

jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.1 (OK)
nbconvert >=4.0  :  4.1.0 (OK)
numpy >=1.7      :  1.11.1 (OK)
pandas >=0.13.1  :  0.17.0 (OK)
pep8 >=0.6       :  1.7.0 (OK)
pyflakes >=0.5.0 :  1.0.0 (OK)
pygments >=2.0   :  2.1.1 (OK)
pylint >=0.25    :  1.5.4 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4 (OK)
sphinx >=0.6.6   :  1.3.5 (OK)
sympy >=0.7.3    :  0.7.6.1 (OK)



Discussion:
We changed how we embed IPython consoles in Spyder 3.0 and this seems to be a byproduct of that.

Since this is a minor (although annoying) issue, I don't think we're going to work on it for now :-)

A not-so-nice workaround is running this script in the background

```
import win32gui
import win32com.client
import time
prev_hwnd = win32gui.GetForegroundWindow()
while True:
    firefox = []
    toplist = []
    winlist = []
    hwnd = win32gui.GetForegroundWindow()
    title =  win32gui.GetWindowText(hwnd)
    if 'nvcc.exe' in title.lower():
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.SendKeys('%')
        win32gui.SetForegroundWindow(prev_hwnd)
        print('Minimized nvcc.exe')
    else:
        prev_hwnd = hwnd

    time.sleep(0.001)
```
takes <1% of CPU and ~6 MB of memory on my machine.
I am experiencing the same issue, although for another application: I run, say 1000-2000, optimizations in a for loop using a solver (cplex or gurobi) which makes an external command promt to pop up, and shut down, for each loop. 

This results in each loop solving much slower than previously (without those pop ups). I have not calculate the difference, but in total we're in the range of 1-3s times 1000-2000 loops.  

Moreover, if you e.g. write in a document with this problem running in the background, you get interrupted every 5'ish second.. Both issues - quite annoying :-) 
If `subprocess` is used to run processes in the background, we could patch it to make it avoid opening new cmd windows.

Resolving patch:
diff --git a/spyder/utils/site/sitecustomize.py b/spyder/utils/site/sitecustomize.py
--- a/spyder/utils/site/sitecustomize.py
+++ b/spyder/utils/site/sitecustomize.py
@@ -195,6 +195,21 @@ def execfile(filename, namespace):
     HAS_CYTHON = False
 
 
+#==============================================================================
+# Prevent subprocess.Popen calls to create visible console windows on Windows.
+# See issue #4932
+#==============================================================================
+if os.name == 'nt':
+    import subprocess
+    creation_flag = 0x08000000  # CREATE_NO_WINDOW
+
+    class SubprocessPopen(subprocess.Popen):
+        def __init__(self, *args, **kwargs):
+            kwargs['creationflags'] = creation_flag
+            super(SubprocessPopen, self).__init__(*args, **kwargs)
+
+    subprocess.Popen = SubprocessPopen
+
 #==============================================================================
 # Importing user's sitecustomize
 #==============================================================================
@@ -227,7 +242,6 @@ def _getfilesystemencoding_wrapper():
     except:
         pass
 
-
 #==============================================================================
 # This prevents a kernel crash with the inline backend in our IPython
 # consoles on Linux and Python 3 (Fixes Issue 2257)


Test patch: