FAQ
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).

Search Discussions

  • Diez B. Roggisch at Mar 18, 2005 at 7:49 pm

    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
  • Markscottwright at Mar 18, 2005 at 9:44 pm
    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?
  • Mike Meyer at Mar 18, 2005 at 10:07 pm

    "markscottwright" <markscottwright at 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 <mwm at mired.org> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
  • Diez B. Roggisch at Mar 19, 2005 at 1:01 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 18, '05 at 6:42p
activeMar 19, '05 at 1:01p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase