Show More
@@ -533,7 +533,7 b' class DebugTools:' | |||||
533 | if name in self.hotnames: |
|
533 | if name in self.hotnames: | |
534 | self.debug_stack( "HotName '%s' caught" % name) |
|
534 | self.debug_stack( "HotName '%s' caught" % name) | |
535 |
|
535 | |||
536 | def launch_new_instance(user_ns = None): |
|
536 | def launch_new_instance(user_ns = None,shellclass = None): | |
537 | """ Make and start a new ipython instance. |
|
537 | """ Make and start a new ipython instance. | |
538 |
|
538 | |||
539 | This can be called even without having an already initialized |
|
539 | This can be called even without having an already initialized | |
@@ -542,7 +542,7 b' def launch_new_instance(user_ns = None):' | |||||
542 | This is also used as the egg entry point for the 'ipython' script. |
|
542 | This is also used as the egg entry point for the 'ipython' script. | |
543 |
|
543 | |||
544 | """ |
|
544 | """ | |
545 | ses = make_session(user_ns) |
|
545 | ses = make_session(user_ns,shellclass) | |
546 | ses.mainloop() |
|
546 | ses.mainloop() | |
547 |
|
547 | |||
548 |
|
548 | |||
@@ -578,7 +578,7 b' def make_user_global_ns(ns = None):' | |||||
578 | return ns |
|
578 | return ns | |
579 |
|
579 | |||
580 |
|
580 | |||
581 | def make_session(user_ns = None): |
|
581 | def make_session(user_ns = None, shellclass = None): | |
582 | """Makes, but does not launch an IPython session. |
|
582 | """Makes, but does not launch an IPython session. | |
583 |
|
583 | |||
584 | Later on you can call obj.mainloop() on the returned object. |
|
584 | Later on you can call obj.mainloop() on the returned object. | |
@@ -591,6 +591,6 b' def make_session(user_ns = None):' | |||||
591 | WARNING: This should *not* be run when a session exists already.""" |
|
591 | WARNING: This should *not* be run when a session exists already.""" | |
592 |
|
592 | |||
593 | import IPython.Shell |
|
593 | import IPython.Shell | |
594 | return IPython.Shell.start(user_ns) |
|
594 | if shellclass is None: | |
595 |
|
595 | return IPython.Shell.start(user_ns) | ||
596 |
|
596 | return shellclass(user_ns = user_ns) |
@@ -6,27 +6,37 b' user namespace.' | |||||
6 | """ |
|
6 | """ | |
7 |
|
7 | |||
8 | import sys |
|
8 | import sys | |
9 |
sys.path. |
|
9 | sys.path.insert(1,'..') | |
10 |
|
10 | |||
11 | import IPython.ipapi |
|
11 | import IPython.ipapi | |
12 |
|
12 | |||
13 | my_ns = dict(a=10) |
|
|||
14 |
|
13 | |||
15 | ses = IPython.ipapi.make_session(my_ns) |
|
|||
16 |
|
14 | |||
17 | # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running |
|
15 | def test_session(shellclass): | |
18 | # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi |
|
16 | print "*****************\nLaunch shell for",shellclass | |
19 |
|
17 | my_ns = dict(a=10) | ||
20 | ip = ses.IP.getapi() |
|
18 | ses = IPython.ipapi.make_session(my_ns) | |
21 |
|
19 | |||
22 | # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython |
|
20 | # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running | |
23 | def mymagic_f(self,s): |
|
21 | # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi | |
24 | print "mymagic says",s |
|
22 | ||
25 |
|
23 | ip = ses.IP.getapi() | ||
26 | ip.expose_magic("mymagic",mymagic_f) |
|
24 | ||
27 |
|
25 | # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython | ||
28 | # And finally, start the IPython interaction! This will block until you say Exit. |
|
26 | def mymagic_f(self,s): | |
29 |
|
27 | print "mymagic says",s | ||
30 | ses.mainloop() |
|
28 | ||
31 |
|
29 | ip.expose_magic("mymagic",mymagic_f) | ||
32 | print "IPython session finished! namespace content:",my_ns |
|
30 | ||
|
31 | # And finally, start the IPython interaction! This will block until you say Exit. | |||
|
32 | ||||
|
33 | ses.mainloop() | |||
|
34 | ||||
|
35 | print "IPython session for shell ",shellclass," finished! namespace content:" | |||
|
36 | for k,v in my_ns.items(): | |||
|
37 | print k,':',str(v)[:80].rstrip() | |||
|
38 | ||||
|
39 | import IPython.Shell | |||
|
40 | ||||
|
41 | test_session(shellclass = None) | |||
|
42 | test_session(IPython.Shell._select_shell(['ipython', '-q4thread'])) |
General Comments 0
You need to be logged in to leave comments.
Login now