Show More
@@ -1,56 +1,61 b'' | |||||
1 | """ Preliminary "job control" extensions for IPython |
|
1 | """ Preliminary "job control" extensions for IPython | |
2 |
|
2 | |||
3 | requires python 2.4 (or separate 'subprocess' module |
|
3 | requires python 2.4 (or separate 'subprocess' module | |
4 |
|
4 | |||
5 | At the moment this is in a very "unhelpful" form, will be extended in the future. |
|
5 | At the moment this is in a very "unhelpful" form, will be extended in the future. | |
6 |
|
6 | |||
7 | Usage: |
|
7 | Usage: | |
8 |
|
8 | |||
9 | [ipython]|2> import jobctrl |
|
9 | [ipython]|2> import jobctrl | |
10 | [ipython]|3> &ls |
|
10 | [ipython]|3> &ls | |
11 | <3> <jobctrl.IpyPopen object at 0x00D87FD0> |
|
11 | <3> <jobctrl.IpyPopen object at 0x00D87FD0> | |
12 | [ipython]|4> _3.go |
|
12 | [ipython]|4> _3.go | |
13 | -----------> _3.go() |
|
13 | -----------> _3.go() | |
14 | ChangeLog |
|
14 | ChangeLog | |
15 | IPython |
|
15 | IPython | |
16 | MANIFEST.in |
|
16 | MANIFEST.in | |
17 | README |
|
17 | README | |
18 | README_Windows.txt |
|
18 | README_Windows.txt | |
19 |
|
19 | |||
20 | ... |
|
20 | ... | |
21 | """ |
|
21 | """ | |
22 |
|
22 | |||
23 | from subprocess import Popen,PIPE |
|
23 | from subprocess import Popen,PIPE | |
|
24 | import os | |||
24 |
|
25 | |||
25 | from IPython import genutils |
|
26 | from IPython import genutils | |
26 |
|
27 | |||
27 | import IPython.ipapi |
|
28 | import IPython.ipapi | |
28 |
|
29 | |||
29 | class IpyPopen(Popen): |
|
30 | class IpyPopen(Popen): | |
30 | def go(self): |
|
31 | def go(self): | |
31 | print self.communicate()[0] |
|
32 | print self.communicate()[0] | |
32 | def __repr__(self): |
|
33 | def __repr__(self): | |
33 | return '<IPython job "%s">' % self.line |
|
34 | return '<IPython job "%s" PID=%d>' % (self.line, self.pid) | |
34 |
|
35 | |||
|
36 | def kill(self): | |||
|
37 | assert os.name == 'nt' # xxx add posix version | |||
|
38 | os.system('taskkill /PID %d' % self.pid) | |||
|
39 | ||||
35 | def startjob(job): |
|
40 | def startjob(job): | |
36 | p = IpyPopen(job, stdout=PIPE) |
|
41 | p = IpyPopen(job, stdout=PIPE, shell = False) | |
37 | p.line = job |
|
42 | p.line = job | |
38 | return p |
|
43 | return p | |
39 |
|
44 | |||
40 | def jobctrl_prefilter_f(self,line): |
|
45 | def jobctrl_prefilter_f(self,line): | |
41 | if line.startswith('&'): |
|
46 | if line.startswith('&'): | |
42 | pre,fn,rest = self.split_user_input(line[1:]) |
|
47 | pre,fn,rest = self.split_user_input(line[1:]) | |
43 |
|
48 | |||
44 | line = ip.IP.expand_aliases(fn,rest) |
|
49 | line = ip.IP.expand_aliases(fn,rest) | |
45 | return '_ip.startjob(%s)' % genutils.make_quoted_expr(line) |
|
50 | return '_ip.startjob(%s)' % genutils.make_quoted_expr(line) | |
46 |
|
51 | |||
47 | raise IPython.ipapi.TryNext |
|
52 | raise IPython.ipapi.TryNext | |
48 |
|
53 | |||
49 | def install(): |
|
54 | def install(): | |
50 | global ip |
|
55 | global ip | |
51 | ip = IPython.ipapi.get() |
|
56 | ip = IPython.ipapi.get() | |
52 | # needed to make startjob visible as _ip.startjob('blah') |
|
57 | # needed to make startjob visible as _ip.startjob('blah') | |
53 | ip.startjob = startjob |
|
58 | ip.startjob = startjob | |
54 | ip.set_hook('input_prefilter', jobctrl_prefilter_f) |
|
59 | ip.set_hook('input_prefilter', jobctrl_prefilter_f) | |
55 |
|
60 | |||
56 | install() No newline at end of file |
|
61 | install() |
General Comments 0
You need to be logged in to leave comments.
Login now