Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc21ee3

Browse files
committed
cleanup up interrupt implementation, added docs
1 parent a3f5c87 commit cc21ee3

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

README.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,35 @@ the line ``let g:ipy_completefunc = 'local'`` in one's vimrc will activate the
164164
IPython-based completion only for current buffer. Setting `g:ipy_completefunc`
165165
to anything other than `'local'` or `'global'` disables it altogether.
166166

167+
**NEW since IPython 0.13**
168+
169+
**Sending ? and ?? now works just like IPython**
170+
This is only supported for single lines that end with ? and ??, which works
171+
just the same as it does in IPython (The ?? variant will show the code, not
172+
just the docstring
173+
174+
**Sending arbitrary signal to IPython kernel**
175+
`:IPythonInterrupt` now supports sending of arbitrary signals. There's a
176+
convenience alias for sending SIGTERM via `:IPythonTerminate`, but you can
177+
also send any signal by just passing an argument to `:IPythonInterrupt`.
178+
Here's an example. First, send this code (or just run it in your kernel)::
179+
180+
import signal
181+
def greeting_user(signum, stack):
182+
import sys
183+
sys.stdout.flush()
184+
print "Hello, USER!"
185+
sys.stdout.flush()
186+
signal.signal(signal.SIGUSR1, greeting_user)
187+
188+
Now, proceed to connect up using vim-ipython and run `:IPythonInterrupt 10` -
189+
where 10 happens to be signal.SIGUSR1 in the POSIX world. This functionality,
190+
along with the sourcing of profile-dependent code on startup (
191+
``vi `ipython locate profile default`/startup/README`` ), brings the forgotten
192+
world of inter-process communication through signals to your favorite text
193+
editor and REPL combination.
194+
195+
167196
---------------
168197
Current issues:
169198
---------------
@@ -242,6 +271,7 @@ pull request with your attribution.
242271
* @pielgrzym for setting completefunc locally to a buffer (#32)
243272
* @flacjacket for pointing out and providing fix for IPython API change
244273
* @memeplex for fixing the identifier grabbing on e.g. non-PEP8 compliant code
274+
* @pydave for IPythonTerminate (sending SIGTERM using our hack)
245275

246276
Similar Projects
247277
----------------

ftplugin/python/ipy.vim

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,19 +492,19 @@ def set_pid():
492492
return pid
493493

494494

495-
def interrupt_kernel_hack():
496-
import signal
497-
send_kernel_interrupt(signal.SIGINT)
498495
def terminate_kernel_hack():
496+
"Send SIGTERM to our the IPython kernel"
499497
import signal
500-
send_kernel_interrupt(signal.SIGTERM)
501-
def send_kernel_interrupt(signal_to_send):
498+
interrupt_kernel_hack(signal.SIGTERM)
499+
500+
def interrupt_kernel_hack(signal_to_send=None):
502501
"""
503502
Sends the interrupt signal to the remote kernel. This side steps the
504503
(non-functional) ipython interrupt mechanisms.
505504
Only works on posix.
506505
"""
507506
global pid
507+
import signal
508508
import os
509509
if pid is None:
510510
# Avoid errors if we couldn't get pid originally,
@@ -514,10 +514,13 @@ def send_kernel_interrupt(signal_to_send):
514514
if pid is None:
515515
echo("cannot get kernel PID, Ctrl-C will not be supported")
516516
return
517+
if not signal_to_send:
518+
signal_to_send = signal.SIGINT
519+
517520
echo("KeyboardInterrupt (sent to ipython: pid " +
518-
"%i with signal %i)" % (pid, signal_to_send),"Operator")
521+
"%i with signal %s)" % (pid, signal_to_send),"Operator")
519522
try:
520-
os.kill(pid, signal_to_send)
523+
os.kill(pid, int(signal_to_send))
521524
except OSError:
522525
echo("unable to kill pid %d" % pid)
523526
pid = None
@@ -650,7 +653,7 @@ endif
650653
command! -nargs=* IPython :py km_from_string("<args>")
651654
command! -nargs=0 IPythonClipboard :py km_from_string(vim.eval('@+'))
652655
command! -nargs=0 IPythonXSelection :py km_from_string(vim.eval('@*'))
653-
command! -nargs=0 IPythonInterrupt :py interrupt_kernel_hack()
656+
command! -nargs=* IPythonInterrupt :py interrupt_kernel_hack("<args>")
654657
command! -nargs=0 IPythonTerminate :py terminate_kernel_hack()
655658

656659
function! IPythonBalloonExpr()

0 commit comments

Comments
 (0)