473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to I restart an interactive session?

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
4 5432
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
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
"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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Joe | last post by:
When you run "python -i scriptname.py" after the script completes you left at the interactive command prompt. Is there a way to have this occur from a running program? In other words can I...
3
by: qwweeeit | last post by:
Hi all, is it possible to enter an interactive session and automatically do some initialization? I explain better: I want that when I start interactive Python on a console (I use Linux) two...
5
by: LL | last post by:
Hi, I use Applicaiton lever variable like this: Application = xxx; Do I need to restart the WWW service every time to reset it? I also have several Session variables. When Session_End event...
2
by: WJ | last post by:
I have three ASPX pages: 1. "WebForm1.aspx" is interactive, responsible for calling a web site (https://www.payMe.com) with $$$. It is working fine. 2. "WebForm2.aspx" is non-interactive, a...
3
by: ad | last post by:
I want to renew all values of Application and Session. How can I restart application in program?
8
by: kenneth fleckenstein nielsen | last post by:
hi guru's I want to restart my webservice when ever it throws an exception that isn't cought. can i do that by web.config or iss or how ??
2
by: Adam Blinkinsop | last post by:
I'm writing a set of modules to monitor remote system services, and I'm having a problem running my test scripts. When I pass the scripts into python, like so: -- $ PYTHONPATH="${TARGET_DIR}"...
9
by: Yasir Zaheer | last post by:
I have made a windows service which is configured to start automatically at the system startup under the USER account type. The service is working perfectly fine when I try to start it manually,...
1
by: Sriram Srivatsan | last post by:
Hi We are trying to build an application where we render some of the .aspx pages from the database using a class derived from System.Web.Hosting.VirtualPathProvider. Users configure the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.