Friday, October 18, 2013

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

在 2013年10月18日星期五UTC+8下午11时12分52秒,ZyX写道:
> > now I redescribe my issue, I want to do some cleanup actions after ctrl-c is pressed. the code is as below:
> > def func():
> > try:
> > while 1:
> > xxx
> > xxx
> > except KeyboardInterrupt:
> > vim.command("xxxx")
> >
> > then the issue occurs, how to resolve it?
>
> If xxx in a while cycle is pure python code (i.e. you did try to interrupt something that does not call vim.*) then it is a part of the known issue that python code is not interruptable. Nobody knows what to do without threads (though MarcWeber have written a patch for the *nix console, but for the gvim threads are needed).
>
> If it is not, then issue apparently was not known. Did you say that it is both vim-7.3 and vim-7.4 issue, though with different exception? The attached patch should fix the issue.
>
>
> Note: it would be much better if you came up with an example with the real code and not xxx: if I see abstract code I evaluate it in mind (and hence e.g. have gotten to false conclusion that KeyboardInterrupt is not thrown). Though still wondering why I said about ignored SIGINT: I was absolutely sure I saw code for ignoring it.
>
>
> # HG changeset patch
> # User ZyX <kp-pav@ya.ru>
> # Date 1382108836 -14400
> # Fri Oct 18 19:07:16 2013 +0400
> # Branch fix-py-vim-interrupt
> # Node ID ce2b5adf52ff9b9ac37749e795d357d8b0a96f47
> # Parent 92c9748e0ccbc42a5e28ce8fb9b8818e756a06da
> Fix interrupt not being properly discarded in VimTryEnd
>
> diff -r 92c9748e0ccb -r ce2b5adf52ff src/if_py_both.h
> --- a/src/if_py_both.h Sun Oct 06 17:46:56 2013 +0200
> +++ b/src/if_py_both.h Fri Oct 18 19:07:16 2013 +0400
> @@ -558,7 +558,11 @@
> /* Keyboard interrupt should be preferred over anything else */
> if (got_int)
> {
> - did_throw = got_int = FALSE;
> + if (current_exception != NULL)
> + discard_current_exception();
> + else
> + need_rethrow = did_throw = FALSE;
> + got_int = FALSE;
> PyErr_SetNone(PyExc_KeyboardInterrupt);
> return -1;
> }
> @@ -567,7 +571,10 @@
> /* Python exception is preferred over vim one; unlikely to occur though */
> else if (PyErr_Occurred())
> {
> - did_throw = FALSE;
> + if (current_exception != NULL)
> + discard_current_exception();
> + else
> + need_rethrow = did_throw = FALSE;
> return -1;
> }
> /* Finally transform VimL exception to python one */

you are right, pure python code in while loop is not interruptable. My code has vim.* in while. hope your patch can resolve the issue, I'll try later, thank you.

--
--
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: