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
Error on leaving IDLE with quit() or exit() under Linux #49742
Comments
Hello developers, Found a small error when using IDLE Version 3.1a1 under Kubuntu Linux See the listing from my installation notes below. Greetings, Ger Let's see if IDLE works, by starting it in the terminal: IDLE works in the new Python version 3.1a1, but there is an error! When leaving IDLE with quit() or exit() and clicking the OK button for Error when leaving with quit() (Full error listing) Object: stderr
Method: <bound method PseudoFile.write of <idlelib.PyShell.PseudoFile
object at 0x9ce942c>>
Args: ('Traceback (most recent call last):',)
Traceback (most recent call last):
File "/usr/local/lib/python3.1/idlelib/rpc.py", line 188, in localcall
ret = method(*args, **kwargs)
File "/usr/local/lib/python3.1/idlelib/PyShell.py", line 1218, in write
self.shell.write(s, self.tags)
File "/usr/local/lib/python3.1/idlelib/PyShell.py", line 1201, in write
self.text.mark_gravity("iomark", "left")
AttributeError: 'NoneType' object has no attribute 'mark_gravity' Error when leaving with exit() (Partial error listing: only the error |
Cannot confirm on Kubuntu 8.04, Python 3.1a2+ built from source, |
I can get a similar error from time to time, just try it a couple of When that error isn't thrown IDLE prints the traceback of a SystemExit The error I am able to get (using 3.1rc2+ r73431): *** Internal Error: rpc.py:SocketIO.localcall() Object: stderr Traceback (most recent call last):
File "/home/gpolo/python-dev/py3k/Lib/idlelib/rpc.py", line 188, in
localcall
ret = method(*args, **kwargs)
File "/home/gpolo/python-dev/py3k/Lib/idlelib/PyShell.py", line 1231,
in write
self.shell.write(s, self.tags)
File "/home/gpolo/python-dev/py3k/Lib/idlelib/PyShell.py", line 1214,
in write
self.text.mark_gravity("iomark", "left")
AttributeError: 'NoneType' object has no attribute 'mark_gravity' I'm not sure if it can't happen in python-trunk too, I see it throws an |
The problem still exists in trunk with 3.2 and 3.3. |
You can trigger this error every time if you change ".after(2*self.poll_interval, self.close2)" to ".after(1, self.close2)" in PyShell.py |
The attached patch fixes the problem. The close method does not need to wait for poll_subprocess rescheduling to stop. The subprocess will be killed, which would cause the socket to timeout. With closing=True, poll_subprocess will return and not reschedule. |
I am presuming 2.7 has same problem since it has same code. The patch appears to give PyShell.close a return value it did not have before. Perhaps remove the return? I am slightly puzzled: self.pollinterval is 50 (millisecs). If reducing the wait from 100 to 1 makes the problem constant, why does reducing it to 0 make it go away? What have I misunderstood? Trying to test on Windows in a 3.3 build, I get the following with or without the patch: >>> exit()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
exit()
File "D:\Python\dev\py33\lib\site.py", line 380, in __call__
raise SystemExit(code)
SystemExit: None def __call__(self, code=None):
# Shells like IDLE catch the SystemExit, but listen when
# stdin wrapper is closed.
try:
fd = -1
if hasattr(sys.stdin, "fileno"):
fd = sys.stdin.fileno()
if fd != 0:
# Don't close stdin if it wraps fd 0
sys.stdin.close()
except:
pass
raise SystemExit(code)
>>> <bare excepts are evil> >>> import sys
>>> hasattr(sys.stdin, "fileno")
True
>>> sys.stdin.fileno
<built-in method fileno of PseudoInputFile object at 0x02893C08>
>>> sys.stdin.fileno()
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
sys.stdin.fileno()
io.UnsupportedOperation: fileno The problem is that PseudoInputFile subclasses PseudoFile which now subclasses TestIOBase without overriding .fileno(), which raises the above. This is from bpo-9290. Bottom line: I believe quit() and exit() are broken in the current 2.7, 3.2, and 3.3 rc's. I will report a possible quick fix on pydev. |
After reading the doc for IOBase.fileno: "Return the underlying file descriptor (an integer) of the stream if it exists. An OSError is raised if the IO object does not use a file descriptor." I decided that the bug is in the assumptions made by site.py. |
I found the root cause of the original error. Entering "exit()" at the shell raises SystemExit which gets written to the shell's text widget. The call to actually write the text passes through .write() in Lib/idlelib/OutputWindow.py, which calls text.update(). The call to .update() enters the Tk event loop and flushes pending events, including expired .after callbacks. Forcing the .after callback in .close() to 1 ms will always trigger the error. Commenting out the text.update() in OutputWindow.py avoids the error. The patch causes .kill_subprocess() to execute immediately which prevents the subprocess from writing to sys.stderr. |
Hello Roger, To you and others that worked on this bug a big thanks for the extra deep Because I'm not familiar with the inner workings that cause this bug I was For me your explanation raised the question if other processes that should Could you shed some light on your bug fix? Greetings, Ger 2013/4/1 Roger Serwy <report@bugs.python.org>
|
Hello Ger, Sure, I can explain. IDLE is driven by the Tk event loop. Calls to .update() flushes all pending events and expired .after callbacks. When close() gets called in PyShell, it places the finalization of the close (using close2()) into the Tk event queue as a .after callback. Now, when the error message arrives over RPC to the PyShell, it is written to the .text widget using the write() method. Here's a snippet from PyShell.py: self.text.mark_gravity("iomark", "right")
count = OutputWindow.write(self, s, tags, "iomark")
self.text.mark_gravity("iomark", "left") The OutputWindow.write() command eventually calls .update() before returning. That .update() call may flush the close2() callback if the timer expired. If so, then .text gets set to None. The next line to restore the gravity to the left is doing an attribute lookup for "mark_gravity" on None which causes the error. I hope that clarifies why the patch works. Can someone verify that the patch works? I've managed to convince myself of its validity, but it is always good to get another set of eyes on it in case I missed something. |
3.4 fresh build, Win 7: Without the patch ^d or window close button [x] quits Idle cleanly.
>>> import idlelib.idle # ^D or [X] in Idle
>>>
With the patch, Idle disappears but console displays error messages. This is an unacceptible regression; something is not right. Sorry ;-).
>>> import idlelib.idle # ^D in idle
>>> invalid command name "53165560callit"
while executing
"53165560callit"
("after" script)
invalid command name "51796472callit"
while executing
"51796472callit"
("after" script)
>>> import idlelib.idle # [X] in Idle
>>> invalid command name "52980280callit"
while executing
"52980280callit"
("after" script) Without or with patch, quit() or exit brings up TK box [Cancel] causes traceback (not good, regression?)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
quit()
File "D:\Python\dev\cpython\lib\site.py", line 356, in __call__
raise SystemExit(code)
SystemExit: None [OK] gives clean exit
>>> import idlelib.idle # quit(), [ok] in idle
>>> Same with 3.3 with from download from repository but without fresh python build (as pcbuild fails). |
Good catch Terry! I've been testing using "python -m idlelib.idle" instead of importing it from an interactive prompt. I'll need to remember to consider that test vector in the future. I figured out why those messages are popping up. The Tk event loop remains running when in the interactive Python REPL due to a PyOS_InputHook driving the Tk loop periodically. Some .after callbacks expire and Tcl tries calling into a Python function that no longer exists. The ColorDelegator's recolorize() and PyShell's poll_subprocess() are the callbacks. (Adding a "print(name, func)" to the after() function in Lib/tkinter/init.py revealed the link between the Tcl reference name and the Python reference name.) The extra ColorDelegator call is actually a bug, related to bpo-13495. (I need to expand it that issue to include this new problem.) Two ColorDelegators get loaded, and only one gets its close() method called which properly cancels the .after callback into recolorize. The "orphaned" ColorDelegator still exists in the delegator chain with an active .after callback. Once both those .after callbacks are canceled, then the error messages Terry sees are no longer shown. The rev1 patch includes extra code to handle cancellation of the poll_subprocess .after callback. I'll be posting the multi-color delegator fix to bpo-13495. |
Hello Roger, Thanks for the clear explanation! Greetings, Ger 2013/4/20 Roger Serwy <report@bugs.python.org>
|
Terry, the SystemExit traceback from clicking cancel is expected given how Lib/site.py's Quitter first closes sys.stdin and then raises SystemExit. Closing sys.stdin causes the dialog, the raised exception just gets printed. We could change the behavior such that when IDLE's internals catch SystemExit, then the close dialog appears. This avoids having to rely on closing sys.stdin to signal IDLE to close. See bpo-17838 for the patch to do just that. (It looks like bpo-17838, bpo-17585, and this issue are converging.) |
New changeset ca8e86711403 by Roger Serwy in branch '2.7': New changeset da852f5250af by Roger Serwy in branch '3.3': New changeset 187da33826eb by Roger Serwy in branch 'default': |
This issue is now fixed. Thank you everyone for helping! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: