Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to I restart an interactive session?

Reply
Thread Tools

How to I restart an interactive session?

 
 
markscottwright
Guest
Posts: n/a
 
      03-18-2005
I'm trying to cobble together an IDLE equivalent using pyshell and VIM
(My idea is just to pipe exec file commands from VIM to pyshell via a
socket or something). The one feature that IDLE has that I would
really like but can't seem to duplicate is the "Restart Shell" command.
Delving through the IDLE code, it looks like IDLE kills and restarts
its InteractiveInterpreter-derived class to do this. Is this really
necessary? If I just take __main__.__dict__ and strip out everything
since a start point, haven't I restored the interpreter to a virgin
state?

(Of course, assuming that there are no threads running, no
c-code-invoked junk lying around, etc).

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-18-2005
markscottwright wrote:

> I'm trying to cobble together an IDLE equivalent using pyshell and VIM
> (My idea is just to pipe exec file commands from VIM to pyshell via a
> socket or something). The one feature that IDLE has that I would
> really like but can't seem to duplicate is the "Restart Shell" command.
> Delving through the IDLE code, it looks like IDLE kills and restarts
> its InteractiveInterpreter-derived class to do this. Is this really
> necessary? If I just take __main__.__dict__ and strip out everything
> since a start point, haven't I restored the interpreter to a virgin
> state?


You can't unload modules, or at least reload is not always working properly.
So - you'd gotta go the road IDLE has gone before I assume.
--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
 
markscottwright
Guest
Posts: n/a
 
      03-18-2005
But, by deleting their namespace entries haven't I effectively unloaded
them? In other words, from the point of the interpreter, isn't the
state at point A and point B the same?

--- point A:
import os
del __main__.__dict__['os']
--- point B

I guess my question boils down to, is the state of the python
interpreter kept anywhere other than the __main__ namespace? Obviously
the answer is yes - there's the current working directory and any
running threads. I think I'm willing to live with those (yeah, I know,
those are the words of a man who is going to spend time chasing obscure
side-effects...)

But are there other things I'm missing? Is my whole plan misguided
from the beginning?

 
Reply With Quote
 
Mike Meyer
Guest
Posts: n/a
 
      03-18-2005
"markscottwright" <(E-Mail Removed)> writes:

> But, by deleting their namespace entries haven't I effectively unloaded
> them? In other words, from the point of the interpreter, isn't the
> state at point A and point B the same?
>
> --- point A:
> import os
> del __main__.__dict__['os']
> --- point B


That depends on the module you import. At point B, sys.modules *will*
contain an entry for the imported module. That won't be true at point
A unless the module was a builtin one.

> I guess my question boils down to, is the state of the python
> interpreter kept anywhere other than the __main__ namespace? Obviously
> the answer is yes - there's the current working directory and any
> running threads. I think I'm willing to live with those (yeah, I know,
> those are the words of a man who is going to spend time chasing obscure
> side-effects...)


Yes. Various things in sys record information about the state of the
interpreter.

> But are there other things I'm missing? Is my whole plan misguided
> from the beginning?


It's not clear that misguided is the correct term. You're trying to do
something with the interpreter that it wasn't designed for. I'd say
that was unwise. Whether or not it *should* have been designed for
what you want to do is another problem.

<mike
--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-19-2005
> But, by deleting their namespace entries haven't I effectively unloaded
> them? In other words, from the point of the interpreter, isn't the


No. You haven't I'm not entirely sure why - that's deep in the internals of
python - but I know for sure that reload() is not working fully as expected
in some cases.

> state at point A and point B the same?
>
> --- point A:
> import os
> del __main__.__dict__['os']
> --- point B
>
> I guess my question boils down to, is the state of the python
> interpreter kept anywhere other than the __main__ namespace? Obviously
> the answer is yes - there's the current working directory and any
> running threads. I think I'm willing to live with those (yeah, I know,
> those are the words of a man who is going to spend time chasing obscure
> side-effects...)
>
> But are there other things I'm missing? Is my whole plan misguided
> from the beginning?


Sort of, as for your comparably little saving of effort you put the burden
of unknown side-effects from your doings on your user. Certainly not the
right thing to do for an IDE, people prefer to trust these
--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Restart the interactive python shell like in IDLE Chris Rebert Python 1 09-30-2013 04:45 PM
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: Restart the interactive python shell like in IDLE Terry Reedy Python 0 06-11-2009 07:04 PM
Restart Now - Restart Later another MickG Computer Support 14 04-24-2006 02:55 AM
XP restart vs msconfig restart Opsimath Computer Support 4 07-31-2005 02:58 PM



Advertisments