Ticket #10476: 10476_singular_interrupt.patch

File 10476_singular_interrupt.patch, 3.9 KB (added by jdemeyer, 10 years ago)
  • sage/interfaces/expect.py

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1340054804 -7200
    # Node ID 9a18427412c38840e0a8a410fb96826cdf28cff3
    # Parent  8c16c23faac0e48277d86b528fd83913982a322d
    Fix interrupting Singular
    
    diff --git a/sage/interfaces/expect.py b/sage/interfaces/expect.py
    a b  
    568568        return
    569569
    570570    def _quit_string(self):
     571        """
     572        Return the string which will be used to quit the application.
     573
     574        EXAMPLES::
     575
     576            sage: gp._quit_string()
     577            '\\q'
     578            sage: maxima._quit_string()
     579            'quit();'
     580        """
    571581        return 'quit'
    572582
     583    def _send_interrupt(self):
     584        """
     585        Send an interrupt to the application.  This is used internally
     586        by :meth:`interrupt`.
     587        """
     588        self._expect.sendline(self._quit_string())
     589        self._expect.sendline(chr(3))
     590
    573591    def _local_tmpfile(self):
    574592        """
    575593        Return a filename that is used to buffer long command lines for this interface
     
    829847            sage: singular._eval_using_file_cutoff = 4
    830848            sage: singular._eval_line('for(int i=1;i<=3;i++){i=1;};', wait_for_prompt=False)
    831849            ''
    832             sage: singular.interrupt(timeout=3)  # sometimes very slow (up to 60s on sage.math, 2012)
    833             False
     850            sage: singular.interrupt()
     851            True
    834852            sage: singular._eval_using_file_cutoff = cutoff
    835853
    836854        Last, we demonstrate that by default the execution of a command
     
    933951        success = False
    934952        try:
    935953            for i in range(tries):
    936                 E.sendline(self._quit_string())
    937                 E.sendline(chr(3))
     954                self._send_interrupt()
    938955                try:
    939956                    E.expect(self._prompt, timeout=timeout)
    940957                    success= True
  • sage/interfaces/singular.py

    diff --git a/sage/interfaces/singular.py b/sage/interfaces/singular.py
    a b  
    99  singular(...), x.[tab] includes all singular commands.
    1010
    1111- Martin Albrecht (2006-03-06): This patch adds the equality symbol to
    12 
     12  singular. Also fix problem in which " " as prompt means comparison
    1313  will break all further communication with Singular.
    1414
    1515- Martin Albrecht (2006-03-13): added current_ring() and
     
    373373        Expect.__init__(self,
    374374                        name = 'singular',
    375375                        prompt = prompt,
    376                         command = "Singular -t --ticks-per-sec 1000", #no tty and fine grained cputime()
     376                        # No tty, fine grained cputime(), don't display CTRL-C prompt
     377                        command = "Singular -t --ticks-per-sec 1000 --cntrlc=a",
    377378                        maxread = maxread,
    378379                        server = server,
    379380                        server_tmpdir = server_tmpdir,
     
    455456        """
    456457        return 'quit'
    457458
     459    def _send_interrupt(self):
     460        """
     461        Send an interrupt and a semi-colon to Singular.
     462
     463        TESTS:
     464
     465        The semi-colon is needed to abort the current input line. The
     466        following works without restarting Singular::
     467
     468            sage: from sage.tests.interrupt import interrupt_after_delay
     469            sage: a = singular(1)
     470            sage: _ = singular._expect.sendline('1+')  # unfinished input
     471            sage: try:
     472            ...    interrupt_after_delay()
     473            ...    singular._expect_expr('>')  # interrupt this
     474            ... except KeyboardInterrupt:
     475            ...     pass
     476            Control-C pressed.  Interrupting Singular. Please wait a few seconds...
     477
     478        We can still access a::
     479
     480            sage: 2*a
     481            2
     482        """
     483        E = self._expect
     484        E.sendline(chr(3))
     485        E.sendline(';')
     486
    458487    def _read_in_file_command(self, filename):
    459488        r"""
    460489        EXAMPLES::