[Python-Dev] IDLE local scope cleanup

Patrick K. O'Brien pobrien@orbtech.com
Wed, 13 Nov 2002 14:16:00 -0600


On Wednesday 13 November 2002 02:00 pm, Guido van Rossum wrote:
> IDLE doesn't use these locals any more; they're decoys.  The GRPC
> version runs the interpreter in a subprocess and the subprocess is
> more careful.

Ah. I suspected that, but didn't understand the subprocess code enough 
to figure that out. Thanks.

Here is my real problem. I used to just pass a regular dictionary to 
code.InteractiveInterpreter, which worked well enough. But I just 
discovered an issue with pickling in the PyCrust shell, illustrated 
below:

Welcome To PyCrust 0.8 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.2.2 (#1, Oct 28 2002, 17:22:19) 
[GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> def foo():
...     pass
...     
>>> pickle.dumps(foo)
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "/usr/local/lib/python2.2/pickle.py", line 978, in dumps
    Pickler(file, bin).dump(object)
  File "/usr/local/lib/python2.2/pickle.py", line 115, in dump
    self.save(object)
  File "/usr/local/lib/python2.2/pickle.py", line 225, in save
    f(self, object)
  File "/usr/local/lib/python2.2/pickle.py", line 519, in save_global
    raise PicklingError(
PicklingError: Can't pickle <function foo at 0x8654b9c>: it's not found 
as __main__.foo
>>> 

So I decided to switch to using sys.modules['__main__'].__dict__, which 
eliminated the pickling error, but introduced a bunch of clutter in the 
local namespace. Any suggestions?

-- 
Patrick K. O'Brien
Orbtech      http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------