python2.5 x python2.6 in interactive mode

Thomas Jollans thomas at jollans.com
Tue Jun 8 10:26:18 EDT 2010


in future please try to reply on-list, not to the person you're replying
to directly.

On 06/08/2010 03:00 PM, Alan wrote:
> Well, using code.interact() didn't help much.
>
> The problem is that one of the reasons (if not the main reason) of
> using 'python -i' is to be able to follow the simulation, i.e., in the
> python terminal I can call commands of our programme and check how is
> the progress of the simulation.
Just an idea: You start a thread that does the work anyway. You could
start another thread for code.interact(), and in the main thread, simply
wait for the simulation thread to finish (maybe with interrupt_main(),
or with a lock/condition...) and then shut everything down from there.
>
> When using code.interact() either my simulation holds until I quit
> (crtl-D and then my simulation starts) the interactive session, or if
> I put code.interact() after the command to start the simulation then I
> never get the python terminal until my simulation is over...
>
> In the end what I need is what "python -i" does, essentially, I need
> code.interact (or maybe IPShellEmbed) to encapsulate my application
> from within the code.
>
> Is it possible?
>
> Thanks,
>
> Alan
>
> On Tue, Jun 8, 2010 at 10:20, Alan <alanwilter at gmail.com
> <mailto:alanwilter at gmail.com>> wrote:
>
>     Thanks Thomas,
>
>     I will give a look at module code.
>
>     Thanks,
>
>     Alan
>
>
>     On Mon, Jun 7, 2010 at 22:42, Thomas Jollans <thomas at jollans.com
>     <mailto:thomas at jollans.com>> wrote:
>
>         On 06/07/2010 01:43 PM, Alan wrote:
>         > Hi there,
>         >
>         > I have a code with a 'exit()' at the end. We run it usually as:
>         >
>         > python2.5 -i code.py
>         >
>         > and if everything is fine, the 'exit()' is called and there's no
>         > interactive terminal.
>         You could instead do something like this:
>
>         try:
>            # ...
>         except:
>            import code
>            code.interact()
>
>         you could even create a stub.py module, like this:
>
>         import runpy
>         import code
>         import sys
>         try:
>            mod_name = sys.argv[1]
>            mod_globals = {}
>            sys.argv = sys.argv[1:]
>            mod_globals = runpy.run_module(mod_name, run_name='__main__',
>         alter_sys=True)
>         except BaseException, e:
>            mod_globals['e'] = e
>            code.interact(mod_globals)
>
>         and run it with python2.6 stub.py code_module
>         though it's probably more useful to just use pdb.pm
>         <http://pdb.pm>() instead of
>         code.interact here... the debugger is your friend!
>         >
>         > However, doing the same above with python2.6 and I got:
>         >
>         > amadeus[2738]:~/TMP% python2.6 -i thread_ping.py
>         > Traceback (most recent call last):
>         >   File "thread_ping.py", line 42, in <module>
>         >     exit()
>         >   File "/sw/lib/python2.6/site.py", line 334, in __call__
>         >     raise SystemExit(code)
>         > SystemExit: None
>         > >>>
>         >
>         > So, everything is fine except that it ended up in the
>         interactive
>         > python terminal. Is there a way of having the very behaviour
>         I have
>         > with python 2.5 for my code in python 2.6?
>         >
>         > Many thanks in advance,
>         >
>         > Alan
>         >
>         > --
>         > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
>         > Department of Biochemistry, University of Cambridge.
>         > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
>         > >>http://www.bio.cam.ac.uk/~awd28
>         <http://www.bio.cam.ac.uk/%7Eawd28>
>         <http://www.bio.cam.ac.uk/%7Eawd28><<
>
>         --
>         http://mail.python.org/mailman/listinfo/python-list
>
>
>
>
>     -- 
>     Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
>     Department of Biochemistry, University of Cambridge.
>     80 Tennis Court Road, Cambridge CB2 1GA, UK.
>     >>http://www.bio.cam.ac.uk/~awd28
>     <http://www.bio.cam.ac.uk/%7Eawd28><<
>
>
>
>
> -- 
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28 <http://www.bio.cam.ac.uk/%7Eawd28><<




More information about the Python-list mailing list