Repository: spyder-ide/spyder

Issue:
Spyder hangs on interactive input in internal console (input is not redirected)
_From [robert.p...@gmail.com](https://code.google.com/u/108043020583786234773/) on 2013-03-21T10:23:20Z_

Spyder Version:  2.1.10
Python Version:  2.7.3
Qt Version:      4.8.2, PyQt4 (API v1) 4.9.3 on Linux 

What steps will reproduce the problem?
1. Open internal console
   1. Write "license()" and press enter What is the expected output? What do you see instead? I expect to see the same as in a regular Python console: The start of the license text and a prompt to press return or q. Instead, I only see the first line of the license and Spyder hangs completely. 

Please provide any additional information below

. This does not happen with the regular Spyder console, the behavior there is as expected.

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1329_



Discussion:
_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2013-03-21T08:46:54Z_

I confirm it. Odd but true.

**Status:** Accepted  
  **Labels:** -Priority-Medium Priority-Critical Cat-SpyderGUI MS-v2.2  

_From [jed.lud...@gmail.com](https://code.google.com/u/114333776555678317161/) on 2013-04-29T15:08:37Z_

**Labels:** MS-v2.2.1  

_From [jed.lud...@gmail.com](https://code.google.com/u/114333776555678317161/) on 2013-04-29T15:10:06Z_

**Labels:** -MS-v2.2  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2013-06-19T13:17:56Z_

**Labels:** -MS-v2.2.1 MS-v2.3  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2013-12-11T12:22:01Z_

**Labels:** MS-v2.3.1  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2013-12-11T12:24:41Z_

**Labels:** -MS-v2.3  

_From [stonebi...@gmail.com](https://code.google.com/u/116068254323340012360/) on 2013-12-12T10:27:58Z_

Apparently, it doesn't hang anymore ?

**\* example below ************

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.7.1, SciPy 0.12.0, Matplotlib 1.3.0
- guidata 1.6.1, guiqwt 2.3.1
  Type "scientific" for more details.
  >>> license()
  A. HISTORY OF THE SOFTWARE

# 

Python was created in the early 1990s by Guido van Rossum at Stichting
Mathematisch Centrum (CWI, see http://www.cwi.nl ) in the Netherlands
as a successor of a language called ABC.  Guido remains Python's
principal author, although it includes many contributions from others.

In 1995, Guido continued his work on Python at the Corporation for
National Research Initiatives (CNRI, see http://www.cnri.reston.va.us )
in Reston, Virginia where he released several versions of the
software.

In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team.  In October of the same
year, the PythonLabs team moved to Digital Creations (now Zope
Corporation, see http://www.zope.com ).  In 2001, the Python Software
Foundation (PSF, see http://www.python.org/psf/ ) was formed, a
non-profit organization created specifically to own Python-related
Intellectual Property.  Zope Corporation is a sponsoring member of
the PSF.

All Python releases are Open Source (see http://www.opensource.org for
Hit Return for more, or q (and Return) to quit: q
>>>

_From [contrebasse](https://code.google.com/u/contrebasse/) on 2014-07-22T11:58:06Z_

It works for me too.

_From [dhoeg...@gmail.com](https://code.google.com/u/100712947103652895129/) on 2014-07-23T07:06:24Z_

I only se this:
>>> license()
See http://www.python.org/download/releases/3.4.1/license And it is not dependant on the type of console, I use python 3.4

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-07-24T06:58:25Z_

But have you tried it in the _internal_ console? I'm still seeing the freeze there.

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-07-24T07:09:52Z_

I think the problem is license() creates an input call to let the user decide if he/she wants to keep reading its text or come back to the prompt, and the Internal Console can't handle it.

_From [contrebasse](https://code.google.com/u/contrebasse/) on 2014-07-24T12:25:15Z_

I have the same thing as dhoegh91, with python 2.7.6 under windows 64bits with spyder 2.3 from anaconda, in both consoles.

I think my previous test was on Linux, and I had the full text.

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-08-17T18:43:53Z_

**Labels:** -MS-v2.3.1 MS-v2.4  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-08-23T13:26:27Z_

issue #864 has been merged into this issue.

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-08-23T13:27:03Z_

**Summary:** Spyder hangs on interactive input in internal console (input is not redirected)  <span class="oldvalue"> (was: license() command in internal console causes Spyder to hang) </span>  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-08-23T13:27:17Z_

**Status:** HelpNeeded  
  **Labels:** -MS-v2.4  

I have same problem.  Typed the following into the internal console:

wait = input("Program paused. Press enter to continue.")

And it printed the message and then Spyder crashed.  This is my first time using Spyder!  Should I be using the internal console for testing code or one of the others?
![screen shot 2015-04-12 at 12 15 39](https://cloud.githubusercontent.com/assets/7958850/7106896/803bde76-e10e-11e4-8085-2926a24eb467.png)

Lost my code!

Spyder 2.3.4 on OS X 10.10.3

The internal console displays a warning about not using it to run your core. You can use an IPython console or a regular python console to run your code.
Thank your for you feedback about this bug (and save your work often !)

@ccordoba12 It doesn't happen with license/license(), etc. since it no longer waits for input, but ``wait = input("Test text")`` indeed perma-hangs Spyder. On one hand, users shouldn't ever enter such code in the internal console and probably won't ever even see it, but on the other hand, an application crash is a pretty severe result that could lead to data loss, time lost recreating the session and user frustration. As I don't see it ever being necessary to actually support ``input()`` in the internal console, is there an easy way to at least prevent the hang at least, even if by catching calls to ``input`` and immediately returning an exception/warning instead of trying to execute them and hanging?
> even if by catching calls to input and immediately returning an exception/warning instead of trying to execute them and hanging?

This is what we should do to prevent people from writing `input` on the internal console.
Do you want to work on it? It could be done for Spyder 3, I think.
I can certainly give it a shot. Any ideas where/when is best to do the check?
Probably here:

https://github.com/spyder-ide/spyder/blob/master/spyder/widgets/shell.py#L278
@dalthviz, very simple one for you. Please avoid people to enter `input` or `raw_input` in the internal console.

Resolving patch:
diff --git a/spyder/widgets/internalshell.py b/spyder/widgets/internalshell.py
--- a/spyder/widgets/internalshell.py
+++ b/spyder/widgets/internalshell.py
@@ -408,10 +408,19 @@ def run_command(self, cmd, history=True, new_prompt=True):
         else:
             if history:
                 self.add_to_history(cmd)
-        self.interpreter.stdin_write.write(to_binary_string(cmd + '\n'))
         if not self.multithreaded:
-            self.interpreter.run_line()
-            self.refresh.emit()
+            if 'input' not in cmd:
+                self.interpreter.stdin_write.write(
+                                                to_binary_string(cmd + '\n'))
+                self.interpreter.run_line()
+                self.refresh.emit()
+            else:
+                self.write(_('In order to use commands like "raw_input" '
+                             'or "input" run Spyder with the multithread '
+                             'option (--multithread) from a system terminal'),
+                           error=True)
+        else:
+            self.interpreter.stdin_write.write(to_binary_string(cmd + '\n'))
     
     
     #------ Code completion / Calltips


Test patch: