By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

How to I restart an interactive session?

P: n/a
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).

Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
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?

Jul 18 '05 #3

P: n/a
"markscottwright" <ma*************@gmail.com> 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 <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #4

P: n/a
> 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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.