[ python-Bugs-1105950 ] idle's stdout is redirected when executing imp.load_source

SourceForge.net noreply at sourceforge.net
Mon Jan 24 03:59:15 CET 2005


Bugs item #1105950, was opened at 2005-01-20 14:08
Message generated for change (Settings changed) made by imperialfists
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1105950&group_id=5470

Category: IDLE
>Group: Not a Bug
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: imperialfists (imperialfists)
Assigned to: Kurt B. Kaiser (kbk)
Summary: idle's stdout is redirected when executing imp.load_source

Initial Comment:
There is a bug in idle caused by load_source, which
switches the stdout of idle to something else.

Here is what I did:
Python 2.3.4 (#1, Nov  2 2004, 11:18:38) 
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1,
ssp-3.3.2-2, pie-8.7.6)] on linux2
[...i leave this out...]
IDLE 1.0.3      
>>> from sys import stdout
>>> print stdout
<idlelib.rpc.RPCProxy instance at 0x407914ac>
>>> print 'a'
a
>>> from imp import load_source
>>> print 'a'
a
>>> print stdout
<idlelib.rpc.RPCProxy instance at 0x407914ac>
>>> m = load_source('bug.py', 'bug.py', open('bug.py'))
>>> print 'a'
>>> print stdout
>>> 

the file 'bug.py' contains the following line:
from types import *

meanwhile i see this on my terminal:
a
<idlelib.rpc.RPCProxy instance at 0x407914ac>

when i type "import bug" or "from bug import *"
everything works fine.
This bug also works (at least for me) if I start idle
from the the "Run Command" dialog under kde, instead of
the terminal.

----------------------------------------------------------------------

Comment By: imperialfists (imperialfists)
Date: 2005-01-24 03:50

Message:
Logged In: YES 
user_id=1201021

I did not always find a file named c either, it was more of
a random occurance, than something reliably reproducable.

----------------------------------------------------------------------

Comment By: Kurt B. Kaiser (kbk)
Date: 2005-01-24 01:10

Message:
Logged In: YES 
user_id=149084

These low level imp module functions don't just import,
they reload() the module.  This destroys the redirection
of stdin, stdout, stderr that IDLE has set up to work with
Tkinter.

Using IDLE without its subprocess, and with verbose
output:

hydra /home/kbk/PYSRC/Lib/idlelib$ ../../python -v ./PyShell.py -n 
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
[...]

In the IDLE shell:

IDLE 1.2a0      ==== No Subprocess ====
>>> import sys
>>> sys.stdout
<__main__.PseudoFile object at 0x42feac>
>>> reload(sys)
>>> sys.stdout
>>> 

And on the console:
[...]
import sys # previously loaded (sys)
<module 'sys' (built-in)>
<open file '<stdout>', mode 'w' at 0xfa068>

imp.load_source() is incompatible with IDLE.
Please use the high level import statements.

I didn't find any extra files.

----------------------------------------------------------------------

Comment By: imperialfists (imperialfists)
Date: 2005-01-21 09:45

Message:
Logged In: YES 
user_id=1201021

Also i find a file named 'c' in my current working directory.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1105950&group_id=5470


More information about the Python-bugs-list mailing list