Loading ...
Sorry, an error occurred while loading the content.

vim.command() always throw exception after KeyboardInterrupt

Expand Messages
  • Yggdroot Chen
    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
    Message 1 of 16 , Oct 17, 2013
    • 0 Attachment
      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.

      Any one knows this issue?

      --
      --
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... The issue is you re trying to prevent the user from rescuing their Vim from a misbehaving command. You are trying to potentially cause data loss when they
      Message 2 of 16 , Oct 17, 2013
      • 0 Attachment
        On Thursday, October 17, 2013 5:14:36 AM UTC-5, Yggdroot Chen 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.
        >
        >
        >
        > Any one knows this issue?

        The issue is you're trying to prevent the user from rescuing their Vim from a misbehaving command. You are trying to potentially cause data loss when they need to force-kill their Vim instead of just stopping a single bad command.

        Don't do that.

        --
        --
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Nikolay Pavlov
        ... raised, vim.command() always throw an exception,which is KeyboardInterrupt in vim7.3 and vim.error in vim7.4. ... SIGINT,but it doesn t work. Interrupt
        Message 3 of 16 , Oct 17, 2013
        • 0 Attachment


          On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archofortune@...> 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.

          > Any one knows this issue?
          >
          > --
          > --
          > 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@....
          > 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@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Yggdroot Chen
          在 2013年10月17日星期四UTC+8下午9时54分53秒,Ben Fritz写道: ... what I want is to prevent ctrl-c from interrupting my program. But there exist
          Message 4 of 16 , Oct 17, 2013
          • 0 Attachment
            在 2013年10月17日星期四UTC+8下午9时54分53秒,Ben Fritz写道:
            > On Thursday, October 17, 2013 5:14:36 AM UTC-5, Yggdroot Chen 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.
            >
            > >
            >
            > >
            >
            > >
            >
            > > Any one knows this issue?
            >
            >
            >
            > The issue is you're trying to prevent the user from rescuing their Vim from a misbehaving command. You are trying to potentially cause data loss when they need to force-kill their Vim instead of just stopping a single bad command.
            >
            >
            >
            > Don't do that.

            what I want is to prevent ctrl-c from interrupting my program. But there exist this issue.

            --
            --
            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@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Yggdroot Chen
            在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道: ... But for my vim7.4.0, ctrl-c can still raise KeyboardInterrupt, then the program
            Message 5 of 16 , Oct 17, 2013
            • 0 Attachment
              在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道:
              > On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archof...@...> 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.
              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 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@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Ben Fritz
              ... WHY do you want to do this? -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
              Message 6 of 16 , Oct 17, 2013
              • 0 Attachment
                On Thursday, October 17, 2013 10:08:19 AM UTC-5, Yggdroot Chen wrote:
                > 在 2013年10月17日星期四UTC+8下午9时54分53秒,Ben Fritz写道:
                > > The issue is you're trying to prevent the user from rescuing their Vim from a misbehaving command. You are trying to potentially cause data loss when they need to force-kill their Vim instead of just stopping a single bad command.
                > > Don't do that.
                >
                > what I want is to prevent ctrl-c from interrupting my program. But there exist this issue.

                WHY do you want to do this?

                --
                --
                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@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Nikolay Pavlov
                ... raised, vim.command() always throw an exception,which is KeyboardInterrupt in vim7.3 and vim.error in vim7.4. ... ignore SIGINT,but it doesn t work.
                Message 7 of 16 , Oct 17, 2013
                • 0 Attachment


                  On Oct 17, 2013 7:46 PM, "Yggdroot Chen" <archofortune@...> wrote:
                  >
                  > 在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道:
                  > > On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archof...@...> 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*.

                  > 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@....
                  > 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@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Nikolay Pavlov
                  ... raised, vim.command() always throw an exception,which is KeyboardInterrupt in vim7.3 and vim.error in vim7.4. ... ignore SIGINT,but it doesn t work.
                  Message 8 of 16 , Oct 17, 2013
                  • 0 Attachment


                    On Oct 17, 2013 8:28 PM, "Nikolay Pavlov" <zyx.vim@...> wrote:
                    >
                    >
                    > On Oct 17, 2013 7:46 PM, "Yggdroot Chen" <archofortune@...> wrote:
                    > >
                    > > 在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道:
                    > > > On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archof...@...> 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@....
                    > > 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@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  • Nikolay Pavlov
                    ... is raised, vim.command() always throw an exception,which is KeyboardInterrupt in vim7.3 and vim.error in vim7.4. ... ignore SIGINT,but it doesn t work.
                    Message 9 of 16 , Oct 17, 2013
                    • 0 Attachment


                      On Oct 17, 2013 9:28 PM, "Nikolay Pavlov" <zyx.vim@...> wrote:
                      >
                      >
                      > On Oct 17, 2013 8:28 PM, "Nikolay Pavlov" <zyx.vim@...> wrote:
                      > >
                      > >
                      > > On Oct 17, 2013 7:46 PM, "Yggdroot Chen" <archofortune@...> wrote:
                      > > >
                      > > > 在 2013年10月17日星期四UTC+8下午10时11分28秒,ZyX写道:
                      > > > > On Oct 17, 2013 5:50 PM, "Yggdroot Chen" <archof...@...> 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).

                      This must mean something like that with your code to ignore signals code to check for interrupt in the GUI is used. I may be wrong though: I do not understand input subsystem well as you can see.

                      > > > 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@....
                      > > > 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@....
                      For more options, visit https://groups.google.com/groups/opt_out.
                    • Yggdroot Chen
                      在 2013年10月18日星期五UTC+8上午12时10分12秒,Ben Fritz写道: ... well,I am writing a vim plugin that need to get input from user, and I want
                      Message 10 of 16 , Oct 17, 2013
                      • 0 Attachment
                        在 2013年10月18日星期五UTC+8上午12时10分12秒,Ben Fritz写道:
                        > On Thursday, October 17, 2013 10:08:19 AM UTC-5, Yggdroot Chen wrote:
                        >
                        > > 在 2013年10月17日星期四UTC+8下午9时54分53秒,Ben Fritz写道:
                        >
                        > > > The issue is you're trying to prevent the user from rescuing their Vim from a misbehaving command. You are trying to potentially cause data loss when they need to force-kill their Vim instead of just stopping a single bad command.
                        >
                        > > > Don't do that.
                        >
                        > >
                        >
                        > > what I want is to prevent ctrl-c from interrupting my program. But there exist this issue.
                        >
                        >
                        >
                        > WHY do you want to do this?

                        well,I am writing a vim plugin that need to get input from user, and I
                        want to define the behavior of ctrl-c.
                        if there is no try-except in while loop, annoying message will be reported as the attachment shows. I want to recover some options after ctrl-c is pressed using vim.command().
                        Anyway, I think this issue is a critical bug.

                        --
                        --
                        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@....
                        For more options, visit https://groups.google.com/groups/opt_out.
                      • Yggdroot Chen
                        在 2013年10月17日星期四UTC+8下午6时14分36秒,Yggdroot Chen写道: ... now I redescribe my issue, I want to do some cleanup actions after ctrl-c
                        Message 11 of 16 , Oct 17, 2013
                        • 0 Attachment
                          在 2013年10月17日星期四UTC+8下午6时14分36秒,Yggdroot Chen写道:
                          > 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.
                          >
                          >
                          >
                          > Any one knows this issue?

                          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?



                          --
                          --
                          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@....
                          For more options, visit https://groups.google.com/groups/opt_out.
                        • ZyX
                          ... 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
                          Message 12 of 16 , Oct 18, 2013
                          • 0 Attachment
                            > 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@...>
                            # 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 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@....
                            For more options, visit https://groups.google.com/groups/opt_out.
                          • ZyX
                            ... Propagated to vim-dev: https://groups.google.com/forum/#!topic/vim_dev/tZQJHSyjAzs. -- -- You received this message from the vim_use maillist. Do not
                            Message 13 of 16 , Oct 18, 2013
                            • 0 Attachment
                              On Friday, October 18, 2013 7:12:52 PM UTC+4, ZyX wrote:
                              > > 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@...>
                              > # 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 */

                              Propagated to vim-dev: https://groups.google.com/forum/#!topic/vim_dev/tZQJHSyjAzs.

                              --
                              --
                              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@....
                              For more options, visit https://groups.google.com/groups/opt_out.
                            • Yggdroot Chen
                              在 2013年10月18日星期五UTC+8下午11时12分52秒,ZyX写道: ... you are right, pure python code in while loop is not interruptable. My code has
                              Message 14 of 16 , Oct 18, 2013
                              • 0 Attachment
                                在 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@...>
                                > # 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@....
                                For more options, visit https://groups.google.com/groups/opt_out.
                              • Yggdroot Chen
                                在 2013年10月19日星期六UTC+8上午1时01分43秒,ZyX写道: ... why can t signal.signal(signal.SIGINT, signal.SIG_IGN) ignore SIGINT, is it a bug?
                                Message 15 of 16 , Oct 23, 2013
                                • 0 Attachment
                                  在 2013年10月19日星期六UTC+8上午1时01分43秒,ZyX写道:
                                  > On Friday, October 18, 2013 7:12:52 PM UTC+4, ZyX wrote:
                                  > > > 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@...>
                                  > > # 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 */
                                  >
                                  > Propagated to vim-dev: https://groups.google.com/forum/#!topic/vim_dev/tZQJHSyjAzs.

                                  why can't "signal.signal(signal.SIGINT, signal.SIG_IGN)" ignore SIGINT, is it a bug?

                                  --
                                  --
                                  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@....
                                  For more options, visit https://groups.google.com/groups/opt_out.
                                • Nikolay Pavlov
                                  ... 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
                                  Message 16 of 16 , Oct 24, 2013
                                  • 0 Attachment


                                    On Oct 24, 2013 6:34 AM, "Yggdroot Chen" <archofortune@...> wrote:
                                    >
                                    > 在 2013年10月19日星期六UTC+8上午1时01分43秒,ZyX写道:
                                    > > On Friday, October 18, 2013 7:12:52 PM UTC+4, ZyX wrote:
                                    > > > > 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@...>
                                    > > > # 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 */
                                    > >
                                    > > Propagated to vim-dev: https://groups.google.com/forum/#!topic/vim_dev/tZQJHSyjAzs.
                                    >
                                    > why can't "signal.signal(signal.SIGINT, signal.SIG_IGN)" ignore SIGINT, is it a bug?

                                    First of all, this is not going to work in the GUI since there are normally no interrupts: ctrl-c is a keyboard event and there is no terminal to throw SIGINT. Thus I would say that any code that relies on ignored SIGINT == ignored interrupts is broken. This signal is also not used when not on *nix due to its unexistence.

                                    I failed to find the code which will set got_int if signal is ignored in the terminal on *nix systems though.

                                    Second, what makes you think that vim should work after you mess with its signals?

                                    > --
                                    > --
                                    > 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@....
                                    > 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@....
                                    For more options, visit https://groups.google.com/groups/opt_out.
                                  Your message has been successfully submitted and would be delivered to recipients shortly.