Thursday, October 17, 2013

Re: vim.command() always throw exception after KeyboardInterrupt


On Oct 17, 2013 8:28 PM, "Nikolay Pavlov" <zyx.vim@gmail.com> wrote:
>
>
> On Oct 17, 2013 7:46 PM, "Yggdroot Chen" <archofortune@gmail.com> wrote:
> >
> > 在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道:
> > > On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archof...@gmail.com> wrote:
> > > >
> > > > I encounter a critical issue when writing vim script using python, for example the code is as below:
> > > >
> > > > def func():
> > > >     try:
> > > >         while 1:
> > > >             xxx
> > > >             xxx
> > > >     except KeyboardInterrupt:
> > > >         pass
> > > >
> > > >     vim.command("xxxx")
> > > >
> > > > I press ctrl-c to interrupt the program, after KeyboardInterrupt is raised, vim.command() always throw an exception,which is KeyboardInterrupt in vim7.3 and vim.error in vim7.4.
> > > >
> > > > I want to use "signal.signal(signal.SIGINT, signal.SIG_IGN)" to ignore SIGINT,but it doesn't work.
> > >
> > > Interrupt signals are already ignored.
> > > vim.command is now "wrapped in a try-catch block" (it is really a pair of C functions). All vim exceptions are transformed into python ones, with vim.error class, and Vim:Interrupt is one of them. Code that was used to transform exceptions did change. You should now catch vim.error and match against error string: got_int apparently is not set inside :try/:catch because interrupts are transformed into exceptions thus code (present in VimTryEnd) that should be preferring raising KeyboardInterrupts over vim.error is useless.
> > > And note that it is currently not possible to interrupt python code in most cases: signals are ignored and input is not polled when running python code.
> > >
> >
> > But for my vim7.4.0, ctrl-c can still raise KeyboardInterrupt, then the program stop running. I don't understand what you said that Interrupt signals are already ignored. Because I have not tried Vim 7.4.052.
>
> Signal handlers are set for SIG_IGN in C code. And this is true for at least vim-7.3.*1*.

No, I am false. SIGINT is not ignored, it just sets got_int and returns. Not applicable for the gui (not because of the absence of handler, but because CTRL-C /= SIGINT here). Have mistaken this with some other signal (there are a few ignored).

> > I want to ignore the KeyboardInterrupt, but signal.signal(signal.SIGINT, signal.SIG_IGN) takes no effect, so I tried the code as mentioned to do nothing when ctrl-c is pressed, then the issue occurs.
>
> You must not interfere with vim signal handlers, behavior of vim will be undefined. But this is no-op because same code is already launched by vim. CTRL-C works not because there are signals working, but because it sees CTRL-C typed.
>
> >
> > --
> > --
> > You received this message from the "vim_use" maillist.
> > Do not top-post! Type your reply below the text you are replying to.
> > For more information, visit http://www.vim.org/maillist.php
> >
> > ---
> > You received this message because you are subscribed to the Google Groups "vim_use" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: