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