-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
IDLE: Don't freeze Shell when user enters sys.stdout.shell.console #78889
Comments
If sys is imported and sys.stdout.shell.console is typed (this is what fail.py does TJR), IDLE does not return to the prompt. Ctrl-C has no effect and after a restart with Ctrl-F6, IDLE does not react after a command is typed in. This also occurs when other variables such as sys.stdout.shell.stdout are used, but not with non-existent variables such as sys.stdout.shell.not_a_variable. No such issue occurs using the command line; however, sys.stdout.shell is not defined in the command line. This behaviour exists in at least Python 3.6.1 and 3.7.0 on Mac OS X 10.9. This might be related to a similar issue that occurs in at least Python 3.2 on Windows 2000. Entering sys.stdout.shell.console causes IDLE to crash immediately; a crash also occurs when you type sys.stdout.shell.console. and wait for IDLE to bring up the list of attributes. I know that this bug shouldn't be encountered unless you're using the IDLE PyShell object for some reason, but it still seems weird that getting the value of a variable causes crashes and hangs, especially when I know that the variable exists from looking at idlelib. This is marked as Python 3.4 to 3.7 because I tested with 3.7, 3.6 and 3.2 and I don't think that this would have been fixed and then broken again. I don't know about 3.8, though. |
Edit: I checked Python 3.4 (Windows XP SP3). It hangs in the same way as Python 3.6/3.7. |
3.4 and 3.5 only get security fixes and I doubt this qualifies. I reproduced the described behavior with 3.7 on Win 10, so it is not Mac-specific. Python sys.stdout: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> Comparing attributes with public names (not starting with single or double underscore) PseudoOutputFile lacks buffer, line_buffering, mode, reconfigure, and write_through. bpo-21995 is about fixing or documenting each omission for all 3 streams. PseudoFiles add attributes 'shell' and 'tags'. Both should have private names that warn users that their behavior is undocumented and usage is at one's own risk. 'shell' should be double underscored. This minimal fix would be sufficient to close this issue. Some manual testing should be sufficient for such a change.
def __getattr__(self, name):
if self.__methods is None:
self.__getmethods()
if self.__methods.get(name):
return MethodProxy(self.sockio, self.oid, name)
if self.__attributes is None:
self.__getattributes()
if name in self.__attributes:
value = self.sockio.remotecall(self.oid, '__getattribute__',
(name,), {})
return value
else:
raise AttributeError(name) Note that self.__attributes is mangled to shell._RPCProxy__attributes when accessed externally. (Also, it is a set still implemented in this ancient code as a dict with int 1 values.) More importantly, remote calls to the Shell console can only pass and return objects that can be pickled, and there is currently no provision for graceful failure. Hence sys.stdout.shell.width is (for me, currently) 80, but .console or .stdout are impossible to return. I am extremely dubious about trying to fix this in the IDLE side of the link. Instead, the proxy should be initialized with sets of known usable attributes and methods. I think the underlying problem is trying to be unnecessarily and impossibly generic. Run only calls the .readline, .write, and .close methods of the console proxy. It only calls stack viewer setup on the interp proxy. A third proxy, for flist, is passed to the stack viewer (I have not yet checked what is needed for that). Restricting proxies to things that are needed and *should* work would make it more feasible to test them. But setting up automated tests would still require some work. |
Terry, I don't see any PseudoOutputFile in the current codebase. Is this out of date? |
Unfortunately, no. The standard stream replacements were renamed to StdOutputFile, etc, and slightly revised, but the buggy behavior remains. The worst is that shell restart does not completely restart the shell. It has to be closed instead. I would like to fix this first by adding 'provision for graceful failure'. 'try' is now nearly free when there is no exception. |
|
3.11.0b5 on Windows:
After 1st Enter, cursor move to blank line and nothing happens. 2nd and 3rd Enters and '...' appears. This seems like a separate bug in secondary prompt mechanism. Otherwise, ^C has no effect, Restart appears to work in that the restart line and a prompt appear, but input does not work. Instead it goes into a secondary prompt loop. A fix is high priority. |
If from sys import stdout
MODE = None
try:
MODE = stdout.shell
except AttributeError:
pass
def mode_write(*args, sep=' ', end='\n', color='stdout'):
"Prints with color if MODE is the IDLE Shell"
if MODE:
_ = MODE.write(sep.join(args) + end, color)
else:
print(*args, sep=sep, end=end)
if __name__ == '__main__':
mode_write('This tends to be blue.')
mode_write('This tends to be red.', color='COMMENT')
mode_write('This tends to be green.', color='STRING') |
Yes. I have recommended |
As near as I can tell, sys.stdxyz.shell is indeed the pyshell.shell instance of pyshell.PyShell, which inherits from outwin.OutputWindow. What is confusing is that shell has a console attribute, which is the pseudofile that prints to the input region of the Shell window, while shell becomes self.tkconsole in the pyshell.ModifiedInterpreter instance and is registered as 'console' in rpc. See I don't think the interp and flist proxies are accessible in the same way that the shell/console proxy is. |
Running IDLE from Command Prompt,
Should check currect doc whether TypeError instead of PicklingError is OK. p is a subclass of Pickler that should not change error types. The dumps call is wrapped as follows:
Will see what happens if TypeError is caught, or whether can convert to AttributeError or even string message. |
Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details.
Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details.
…thonGH-121876) Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details. (cherry picked from commit 58753f3) Co-authored-by: Terry Jan Reedy <[email protected]>
…thonGH-121876) Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details. (cherry picked from commit 58753f3) Co-authored-by: Terry Jan Reedy <[email protected]>
…H-121876) (#121912) gh-78889: Stop IDLE Shell freezes from sys.stdout.shell.xyz (GH-121876) Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details. (cherry picked from commit 58753f3) Co-authored-by: Terry Jan Reedy <[email protected]>
…H-121876) (#121911) gh-78889: Stop IDLE Shell freezes from sys.stdout.shell.xyz (GH-121876) Problem occurred when attribute xyz could not be pickled. Since this is not trivial to selectively fix, block all attributes (other than 'width'). IDLE does not access them and they are private implementation details. (cherry picked from commit 58753f3) Co-authored-by: Terry Jan Reedy <[email protected]>
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:
Linked PRs
The text was updated successfully, but these errors were encountered: