##// END OF EJS Templates
remove outdated examples
remove outdated examples

File last commit:

r375:daec54f1
r495:87a6feaf
Show More
jobctrl.py
60 lines | 1.5 KiB | text/x-python | PythonLexer
vivainio
Add jobctrl.py extension
r372 """ Preliminary "job control" extensions for IPython
requires python 2.4 (or separate 'subprocess' module
At the moment this is in a very "unhelpful" form, will be extended in the future.
Usage:
[ipython]|2> import jobctrl
[ipython]|3> &ls
<3> <jobctrl.IpyPopen object at 0x00D87FD0>
[ipython]|4> _3.go
-----------> _3.go()
ChangeLog
IPython
MANIFEST.in
README
README_Windows.txt
...
"""
from subprocess import Popen,PIPE
vivainio
add 'kill' to jobctrl
r375 import os
vivainio
Add jobctrl.py extension
r372
from IPython import genutils
vivainio
jobctrl: publish in _ip namespace after installation
r373 import IPython.ipapi
vivainio
Add jobctrl.py extension
r372 class IpyPopen(Popen):
def go(self):
print self.communicate()[0]
vivainio
jobctrl: publish in _ip namespace after installation
r373 def __repr__(self):
vivainio
add 'kill' to jobctrl
r375 return '<IPython job "%s" PID=%d>' % (self.line, self.pid)
vivainio
Add jobctrl.py extension
r372
vivainio
add 'kill' to jobctrl
r375 def kill(self):
assert os.name == 'nt' # xxx add posix version
os.system('taskkill /PID %d' % self.pid)
vivainio
jobctrl: publish in _ip namespace after installation
r373 def startjob(job):
vivainio
add 'kill' to jobctrl
r375 p = IpyPopen(job, stdout=PIPE, shell = False)
vivainio
Add jobctrl.py extension
r372 p.line = job
return p
def jobctrl_prefilter_f(self,line):
if line.startswith('&'):
vivainio
Aliases are no transitive, i.e. expand recursively
r374 pre,fn,rest = self.split_user_input(line[1:])
line = ip.IP.expand_aliases(fn,rest)
return '_ip.startjob(%s)' % genutils.make_quoted_expr(line)
vivainio
Add jobctrl.py extension
r372
raise IPython.ipapi.TryNext
vivainio
jobctrl: publish in _ip namespace after installation
r373 def install():
vivainio
Aliases are no transitive, i.e. expand recursively
r374 global ip
vivainio
jobctrl: publish in _ip namespace after installation
r373 ip = IPython.ipapi.get()
# needed to make startjob visible as _ip.startjob('blah')
ip.startjob = startjob
ip.set_hook('input_prefilter', jobctrl_prefilter_f)
install()