Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console hangs on 'run' command. #502

Closed
spyder-bot opened this issue Feb 16, 2015 · 29 comments
Closed

console hangs on 'run' command. #502

spyder-bot opened this issue Feb 16, 2015 · 29 comments

Comments

@spyder-bot
Copy link
Collaborator

From christop...@gmail.com on 2010-12-15T06:47:05Z

What steps will reproduce the problem?

  1. with any script in editor, configure to run in current ipython interpreter
    1. hit F5 (run), do it a couple of times
    2. console will hang (not responding to ^C anymore) What is the expected output? What do you see instead? script runs an prompt reappears. Instead the console hangs. What version of the product are you using? On what operating system? spyder-2.0.3, OS X 10.6.4, python 2.6.1

Please provide any additional information below

. if runfile(....) is typed on the console, hang does not occur.

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=502

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2010-12-15T05:56:02Z

issue #438 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2010-12-15T10:10:51Z

Status: New

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-03-13T04:35:36Z

This issue was closed by revision 970c3cca35 .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From christop...@gmail.com on 2011-03-21T02:46:47Z

I don't see why issue #438 is related. The hang upon hitting F5 is not fixed here. Spyder 2.1.0dev, Python 2.6.1, Qt 4.6.3, PyQt 4.7.4 on Darwin.

Status: Started

@spyder-bot
Copy link
Collaborator Author

From christop...@gmail.com on 2011-03-24T03:30:13Z

... I found that the console also hangs when pasting text into it. e.g. paste the following into console

x=arange(0,10,0.1)
y=arange(0,5,0.1)


(including newline) and console will hang.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-03-24T07:28:57Z

I can't reproduce this last behavior, nor the first one reported in this bug. I use F5 a lot and I've never seen a console hang.

Maybe this is just a Mac related problem (because I work on Linux). I'll try to check on Windows during the weekend.

Carlos

@spyder-bot
Copy link
Collaborator Author

From christop...@gmail.com on 2011-03-24T17:14:22Z

Yes, I also think this bug is OS X specific. I have not seen this on Windows. Maybe a bug in QT itself? ...

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-03-24T20:18:11Z

Can you see something printed on the internal console before the hang? That could help to solve this mystery :-)

@spyder-bot
Copy link
Collaborator Author

From Chris.J....@gmail.com on 2011-03-25T05:07:49Z

I too have the same issue. Running code from the script in ipython console (and the python console) using 'F5' or 'F9' causes console to hang, as if awaiting more input, but without the '...:' prompt. The cursor just flashes at the far left of the console window, accepting new keyboard input, but displaying no output or prompt of any kind.

I have also observed however occasionally, that running an erroneous script does work, well at least keeps the console alive after trying to execute it.

Example: open a ipython console and new script with the single line: x() = 20 , and execute with F5 or F9.

However this behaviour is not consistent, and quite often also causes the same issue, especially if tried twice in a row on the same console window. Not sure if this helps, but thought I'd report it.

I can also verify that the same issue happens when pasting multi-line code into the console window. Single lines of code when copy and pasted in seem to work fine.

Also think this bug is Mac specific, as have been using latest version of spyder on windows fine before now.

I'm running spyder 2.0.8, on Mac OS X 10.6.6 (Darwin 10.6.0), with:
python 2.6.1,
ipython 0.10,
PyQt 4.8.3,
Qt 4.7.2.


Chris

@spyder-bot
Copy link
Collaborator Author

From christop...@gmail.com on 2011-03-25T08:52:11Z

I have looked into this a little further:

the console hangs in the externalshell.pythonshell.execute_lines(), when calling self.emit(SIGNAL("wait_for_ready_read()")). Commenting the line out makes the hang
disappear (but of course everything else goes wrong...). Since I don't understand
the systematic behind the IPC of spyder and the externalconsole, I won't continue here but will be happy to provide additional information if necessary. As I don't care for copying multiline text into the console so much, I just commented the line that emits the signal there. Without it there are no hangs after pressing F5.

Christoph.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-03-26T07:24:53Z

@-Chris: Thanks for confirming this is a problem that affects all OS X users.

@-Chirstoph: Thanks a lot for digging further to solve this problem. This is quite an improvement. The only one that really knows how the IPC protocol works is Pierre, but I'll take a look at it to see if I can find something suspicious.

Labels: -Priority-Medium Priority-Critical OpSys-OSX

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-03-27T07:02:26Z

I've tried (and failed) finding an alternative solution to the "wait_for_ready_read()" signal -- which is necessary to wait for the interpreter to be ready for next line execution.

It's going to be very difficult to debug knowing that I've currently only access to Linux or Windows machines.

But I'll think about it.

BTW, I might be wrong but commenting this line should only affect the display: executed lines (inputs) should be printed out together instead of the expected alternate display of inputs/outputs.

@spyder-bot
Copy link
Collaborator Author

From christop...@gmail.com on 2011-03-28T03:02:06Z

I guess you are right regarding commenting that line. That it should
only affect the output.
But: this is not what happens when I paste text here (and wait_for_ready_read() is not emitted):
--- clipboard content ---
from time import time, sleep, clock
t = 1234
----------- end --------------
I enter a command:
In [1]: a = 'toll'

In [2]:

and then I paste and get:
In [2]: from time import time, sleep, clock
t = 1234

In [3]:
In [4]: ------------------------------------------------------------
File "", line 1
In [2]: from time import time, sleep, clock
^
SyntaxError: invalid syntax

In [5]:
In [6]:

Notably, the 'In [2]:' prompt turns grey, which indicates to me that it is falsely taken as input.

@spyder-bot
Copy link
Collaborator Author

From petrus.h...@gmail.com on 2011-04-10T12:58:55Z

I experience this on mac osx 10.6 too.

One line of "run selected text" works, it pastest into ipython and executes. Next entered line to ipython, regardelss via run selected text or direct entering of command, makes it go into a non-communicative mode. The task clock is still ticking.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-04-24T07:38:06Z

This issue was closed by revision 970c3cca35f9 .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From petrus.h...@gmail.com on 2011-04-24T13:40:43Z

The cut-n-paste and run selection issue still seems to be there in mac osx.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-05-02T07:48:37Z

I'm reopening this issue because I don't think the mentioned revision fixed it. It just changes the console encoding and nothing else.

Besides, Petrush has confirmed the bug is still present.

Status: Accepted

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-05-15T19:40:47Z

Labels: Cat-Console

@spyder-bot
Copy link
Collaborator Author

From Eric.Lub...@gmail.com on 2011-11-21T13:27:09Z

Issue still present in OS X 10.7

@spyder-bot
Copy link
Collaborator Author

From tomash.k...@seznam.cz on 2011-12-08T09:55:52Z

This really unfortunate, the described bug is still there which renders spyder pointless. I used to enjoy working in spyder on Linux and Windows, but now I am stuck having to use Mac... without spyder:(

What I care about the most is executing parts of script by F9 (run block/selection). What happens is that no matter the interpreter it does not work after pressing it just two times - first time it executes correctly, second time it either "freezes" (python) or crashes (ipython).

There is no information printed to the console, or to the in internal console, that would explain what is going on. If some additional info is needed to debug, or you can provide instructions on how to debug, please ask/tell.

OS X 10.6.8
spyder 2.1.2
pyqt 4.8.6
python 2.7.2
ipython 0.11
qt 4.7.4

@spyder-bot
Copy link
Collaborator Author

From techtonik@gmail.com on 2011-12-09T07:02:38Z

You can help to insert relevant debug statements in Spyder code that in --debug mode will provide a sane log for everything that happens after 'Run' action is executed.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-09T08:25:11Z

You can see at comment #11 that Christoph already has identified the problem. I came to the same conclusion independently after trying to solve this issue.

So all people who wants a workaround to this problem, please comment line 62 of file spyderlib/widgets/externalshell/pythonshell.py, which reads like this:

self.emit(SIGNAL("wait_for_ready_read()"))

and is part of method execute_lines of class ExtPythonShellWidget.

Doing this you'll see that text appearing in the console won't preserve indentation and because of that won't look rightly formatted, but it'll be evaluated without problems.

In the meantime I'll keep working to find a proper solution

Status: Started

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-09T13:47:33Z

I have now a real patch for this bug:

diff -r c6adff9c2b3f spyderlib/widgets/externalshell/pythonshell.py
--- a/spyderlib/widgets/externalshell/pythonshell.py Thu Dec 08 18:19:29 2011 -0500
+++ b/spyderlib/widgets/externalshell/pythonshell.py Fri Dec 09 16:37:20 2011 -0500
@@ -59,7 +59,11 @@
continue
self.write(line+os.linesep, flush=True)
self.execute_command(line)

  •        self.emit(SIGNAL("wait_for_ready_read()"))
    
  •        if sys.platform.startswith("darwin"):
    
  •            import time
    
  •            time.sleep(0.025)
    
  •        else:
    
  •            self.emit(SIGNAL("wait_for_ready_read()"))
         self.flush()
    

    #------ Code completion / Calltips

Please, all interested people try it and tell us if it works for you. We want this to go in the next release.

Pierre, I don't understand why the signal hangs the console (it seems that text comes faster from the external process than can be processed by Spyder). Is it equivalent to use time.sleep to bypass this?

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-12-10T00:08:58Z

Carlos, I'm not sure to understand what's going wrong here, but could you try to set a reference to the process in the python shell and call directly the self.process.waitForReadyRead callback instead of doing it through the signal, just in case.

So that would be the following, from the current spyderlib/widgets/externalshell/pythonshell.py:

In ExternalPythonShell/create_process:

replace this:

    self.connect(self.shell, SIGNAL("wait_for_ready_read()"),
                 lambda: self.process.waitForReadyRead(250))

by this:

    self.shell.process = self.process  # this is ugly, but just temporary

and in ExtPythonShellWidget/execute_lines:

replace this:

        self.emit(SIGNAL("wait_for_ready_read()"))

by this:

        self.process.waitForReadyRead(250)

@spyder-bot
Copy link
Collaborator Author

From tomash.k...@seznam.cz on 2011-12-10T05:14:47Z

The sleep patch by Carlos soles both the hanging (python) and crashing (ipython) for me. Thanks a lot, this was fast:)

I have also tested the changes proposed by Pierre, but these do not solve the bug. Somehow, to me it seems that the call to self.process.waitForReady() is the cause, would it make any sense?

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-12-10T07:12:13Z

That's great news. Let's go for it.

It's difficult for me to propose something meaningful for this issue as I don't have the opportunity to work on MacOS and the call to self.process.waitForReady is useful on other platforms -- I don't really understand why it does not work on MacOS, perhaps the implementation of QProcess is slighty different on this platform.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-10T07:25:17Z

Thanks Tomash. Not as fast as we'd liked it (the issue was filed a year ago!) but at least it was not as hard as I thought.

Pierre, I looked for problems of waitForReadyRead on OS X but found none with QProcess. However I read some people has issues with this method in other classes and use the solution I proposed.

I'll push the patch this afternoon so this can go in 2.1.5

@spyder-bot
Copy link
Collaborator Author

From Potdevin...@gmail.com on 2011-12-10T15:15:24Z

Probably a bit late, but I also would like to confirm that the patch does do the job, with the regular python console as well as ipython.

Thanks a lot for that!

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-11T09:30:38Z

This issue was updated by revision 3f8ce1c6b6c1 .

-. Emmiting wait_for_ready_read was making the console hang in OS X. So we just
use time.sleep to do the same, i.e. wait a little bit until a line is executed
and returned by the external console process before sending it a new one.

-. It works for python and ipython consoles.

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant