Ticket #10296: trac_10296-restart_if_needed.patch

File trac_10296-restart_if_needed.patch, 11.5 KB (added by mhansen, 7 years ago)
  • sage/interfaces/axiom.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1324219260 0
    # Node ID 6d320723000553d1ce792151e6a47614f16762b9
    # Parent  40c0b143e632e777f0830ed3f6c1440b68fbb226
    [mq]: trac_10296-restart_if_needed.patch
    
    diff --git a/sage/interfaces/axiom.py b/sage/interfaces/axiom.py
    a b  
    411411        return s
    412412
    413413    def _eval_line(self, line, reformat=True, allow_use_file=False,
    414                    wait_for_prompt=True, first_call=False):
     414                   wait_for_prompt=True, restart_if_needed=False):
    415415        """
    416416        EXAMPLES::
    417417       
  • sage/interfaces/expect.py

    diff --git a/sage/interfaces/expect.py b/sage/interfaces/expect.py
    a b  
    670670    def _read_in_file_command(self, filename):
    671671        raise NotImplementedError
    672672
    673     def _eval_line_using_file(self, line, first_call=True):
     673    def _eval_line_using_file(self, line, restart_if_needed=True):
    674674        """
    675675        Evaluate a line of commands, using a temporary file.
    676676
     
    686686        INPUT:
    687687
    688688        - ``line`` -- (string) a command.
    689         - ``first_call`` - (optional bool, default ``True``) --
     689        - ``restart_if_needed`` - (optional bool, default ``True``) --
    690690          If it is ``True``, the command evaluation is evaluated
    691691          a second time after restarting the interface, if an
    692692          EOFError occured.
     
    706706            3
    707707            sage: singular.eval('quit;')
    708708            ''
    709             sage: singular._eval_line_using_file('def a=3;', first_call=False)
     709            sage: singular._eval_line_using_file('def a=3;', restart_if_needed=False)
    710710            Traceback (most recent call last):
    711711            ...
    712712            RuntimeError: Singular terminated unexpectedly while reading in a large line
     
    728728            self._send_tmpfile_to_server()
    729729            tmp_to_use = self._remote_tmpfile()
    730730        try:
    731             s = self._eval_line(self._read_in_file_command(tmp_to_use), allow_use_file=False, first_call=False)
     731            s = self._eval_line(self._read_in_file_command(tmp_to_use), allow_use_file=False, restart_if_needed=False)
    732732        except pexpect.EOF, msg:
    733733            if self._quit_string() in line:
    734734                # we expect to get an EOF if we're quitting.
    735735                return ''
    736             elif first_call==True: # the subprocess might have crashed
     736            elif restart_if_needed==True: # the subprocess might have crashed
    737737                try:
    738738                    self._synchronize()
    739                     return self._post_process_from_file(self._eval_line_using_file(line, first_call=False))
     739                    return self._post_process_from_file(self._eval_line_using_file(line, restart_if_needed=False))
    740740                except RuntimeError, msg:
    741741                    raise RuntimeError, '%s terminated unexpectedly while reading in a large line:\n%s'%(self,msg[0])
    742742                except TypeError:
     
    747747                if self._expect is None or not self._expect.isalive():
    748748                    return ''
    749749                raise
    750             if first_call==True and (self._expect is None or not self._expect.isalive()):
     750            if restart_if_needed==True and (self._expect is None or not self._expect.isalive()):
    751751                try:
    752752                    self._synchronize()
    753                     return self._post_process_from_file(self._eval_line_using_file(line, first_call=False))
     753                    return self._post_process_from_file(self._eval_line_using_file(line, restart_if_needed=False))
    754754                except TypeError:
    755755                    pass
    756756                except RuntimeError, msg:
     
    763763    def _post_process_from_file(self, s):
    764764        return s
    765765
    766     def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=True):
     766    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=True):
    767767        """
    768768        Evaluate a line of commands.
    769769
     
    787787          allow to evaluate long commands using :meth:`_eval_line_using_file`.
    788788        - ``wait_for_prompt`` (optional bool, default ``True``) --
    789789          wait until the prompt appears in the sub-process' output.
    790         - ``first_call`` (optional bool, default ``True``) --
     790        - ``restart_if_needed`` (optional bool, default ``True``) --
    791791          If it is ``True``, the command evaluation is evaluated
    792792          a second time after restarting the interface, if an
    793793          EOFError occured.
     
    828828
    829829            sage: singular.eval('quit;')
    830830            ''
    831             sage: singular._eval_line_using_file('def a=3;', first_call=False)
     831            sage: singular._eval_line_using_file('def a=3;', restart_if_needed=False)
    832832            Traceback (most recent call last):
    833833            ...
    834834            RuntimeError: Singular terminated unexpectedly while reading in a large line
     
    857857               
    858858            except OSError, msg:
    859859                if not E.isalive():
    860                     if first_call==True: # the subprocess might have crashed
     860                    if restart_if_needed==True: # the subprocess might have crashed
    861861                        try:
    862862                            self._synchronize()
    863                             return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, first_call=False)
     863                            return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, restart_if_needed=False)
    864864                        except (TypeError, RuntimeError):
    865865                            pass
    866866                raise RuntimeError, "%s\nError evaluating %s in %s"%(msg, line, self)
     
    884884                    if self._quit_string() in line:
    885885                        # we expect to get an EOF if we're quitting.
    886886                        return ''
    887                     elif first_call==True: # the subprocess might have crashed
     887                    elif restart_if_needed==True: # the subprocess might have crashed
    888888                        try:
    889889                            self._synchronize()
    890                             return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, first_call=False)
     890                            return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, restart_if_needed=False)
    891891                        except (TypeError, RuntimeError):
    892892                            pass
    893893                    raise RuntimeError, "%s\n%s crashed executing %s"%(msg,self, line)
  • sage/interfaces/gap.py

    diff --git a/sage/interfaces/gap.py b/sage/interfaces/gap.py
    a b  
    465465        self.quit()
    466466        raise KeyboardInterrupt, "Ctrl-c pressed while running %s"%self
    467467
    468     def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=True):
     468    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=True):
    469469        """
    470470        Evaluate a line of commands.
    471471
     
    489489          allow to evaluate long commands using :meth:`_eval_line_using_file`.
    490490        - ``wait_for_prompt`` (optional bool, default ``True``) --
    491491          wait until the prompt appears in the sub-process' output.
    492         - ``first_call`` (optional bool, default ``True``) --
     492        - ``restart_if_needed`` (optional bool, default ``True``) --
    493493          If it is ``True``, the command evaluation is evaluated
    494494          a second time after restarting the interface, if an
    495495          EOFError occured.
  • sage/interfaces/gp.py

    diff --git a/sage/interfaces/gp.py b/sage/interfaces/gp.py
    a b  
    371371        """
    372372        return self.set_default('seriesprecision', prec)
    373373
    374     def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=False):
     374    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
    375375        """
    376376        EXAMPLES::
    377377       
  • sage/interfaces/kash.py

    diff --git a/sage/interfaces/kash.py b/sage/interfaces/kash.py
    a b  
    503503
    504504    # Change the default for KASH, since eval using a file doesn't
    505505    # work except for setting variables.
    506     def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True, first_call=False):
     506    def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True, restart_if_needed=False):
    507507        return Expect._eval_line(self, line, allow_use_file=allow_use_file,
    508508                                 wait_for_prompt=wait_for_prompt)
    509509
  • sage/interfaces/lie.py

    diff --git a/sage/interfaces/lie.py b/sage/interfaces/lie.py
    a b  
    609609        except KeyError:
    610610            return "Could not find help for " + command
    611611
    612     def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=False):
     612    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
    613613        """
    614614        EXAMPLES:
    615615            sage: lie._eval_line('2+2') #optional -- requires LiE
  • sage/interfaces/maple.py

    diff --git a/sage/interfaces/maple.py b/sage/interfaces/maple.py
    a b  
    534534                sage.misc.persist.save(v, COMMANDS_CACHE)
    535535            return v
    536536
    537     def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=False):
     537    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
    538538        """
    539539        EXAMPLES::
    540540       
  • sage/interfaces/mathematica.py

    diff --git a/sage/interfaces/mathematica.py b/sage/interfaces/mathematica.py
    a b  
    534534    #    """
    535535    #    self.eval('Clear[%s]'%var)
    536536
    537     def _eval_line(self, line,  allow_use_file=True, wait_for_prompt=True, first_call=False):
     537    def _eval_line(self, line,  allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
    538538        s = Expect._eval_line(self, line,
    539539             allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt)
    540540        return str(s).strip('\n')
  • sage/interfaces/maxima.py

    diff --git a/sage/interfaces/maxima.py b/sage/interfaces/maxima.py
    a b  
    714714            raise KeyboardInterrupt, msg
    715715
    716716    def _eval_line(self, line, allow_use_file=False,
    717                    wait_for_prompt=True, reformat=True, error_check=True, first_call=False):
     717                   wait_for_prompt=True, reformat=True, error_check=True, restart_if_needed=False):
    718718        """
    719719        Return result of line evaluation.
    720720
  • sage/interfaces/mupad.py

    diff --git a/sage/interfaces/mupad.py b/sage/interfaces/mupad.py
    a b  
    236236        return AsciiArtString(s)
    237237
    238238    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True,
    239                    need_output=True, first_call=False):
     239                   need_output=True, restart_if_needed=False):
    240240        """
    241241        EXAMPLES:
    242242            sage: mupad._eval_line('2+2')  # optional - mupad
  • sage/interfaces/qepcad.py

    diff --git a/sage/interfaces/qepcad.py b/sage/interfaces/qepcad.py
    a b  
    10961096            raise AttributeError
    10971097        return QepcadFunction(self, attrname)
    10981098
    1099     def _eval_line(self, cmd, first_call=False):
     1099    def _eval_line(self, cmd, restart_if_needed=False):
    11001100        r"""
    11011101        Send a command to QEPCAD, wait for a prompt, and return the
    11021102        text printed by QEPCAD before the prompt.  Not intended for