How to I restart an interactive session?

Discussion in 'Python' started by markscottwright, Mar 18, 2005.

  1. 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).
    markscottwright, Mar 18, 2005
    #1
    1. Advertising

  2. 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
    Diez B. Roggisch, Mar 18, 2005
    #2
    1. Advertising

  3. 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?
    markscottwright, Mar 18, 2005
    #3
  4. markscottwright

    Mike Meyer Guest

    "markscottwright" <> 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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, Mar 18, 2005
    #4
  5. > 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
    Diez B. Roggisch, Mar 19, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Simpson

    HELP! How to handle Session Restart on Logon

    Harry Simpson, Aug 14, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    381
    Guenther Liebowitz
    Aug 14, 2003
  2. WJ
    Replies:
    2
    Views:
    475
  3. Chris Rebert
    Replies:
    1
    Views:
    1,119
    Ricardo Abreu
    Sep 30, 2013
  4. Terry Reedy
    Replies:
    0
    Views:
    625
    Terry Reedy
    Jun 11, 2009
  5. Josef Moellers

    Restart Perl Application upon KDE Restart

    Josef Moellers, Jul 18, 2013, in forum: Perl Misc
    Replies:
    18
    Views:
    261
    Adam H. Kerman
    Jul 26, 2013
Loading...

Share This Page