Ticket #10296: trac10296_expect_on_nonlinux.patch

File trac10296_expect_on_nonlinux.patch, 8.1 KB (added by SimonKing, 8 years ago)

Make the automatic restart of pexpect interfaces work on non-linux machines

  • sage/interfaces/axiom.py

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1304498774 -7200
    # Node ID 1b007cbcac3b47cdbea61646340aaffa7cf611d2
    # Parent  a6f00668934c0580be551953e7ede7d03909ed5e
    #10296: Cope with non-linux error types raised at crashed pexpect interfaces
    
    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):
     414                   wait_for_prompt=True, first_call=False):
    415415        """
    416416        EXAMPLES::
    417417       
  • sage/interfaces/expect.py

    diff --git a/sage/interfaces/expect.py b/sage/interfaces/expect.py
    a b  
    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)
     731            s = self._eval_line(self._read_in_file_command(tmp_to_use), allow_use_file=False, first_call=False)
    732732        except pexpect.EOF, msg:
    733733            if self._quit_string() in line:
    734734                # we expect to get an EOF if we're quitting.
     
    736736            elif first_call==True: # the subprocess might have crashed
    737737                try:
    738738                    self._synchronize()
    739                     return self._eval_line_using_file(line, first_call=False)
    740                 except (TypeError, RuntimeError):
     739                    return self._post_process_from_file(self._eval_line_using_file(line, first_call=False))
     740                except RuntimeError, msg:
     741                    raise RuntimeError, '%s terminated unexpectedly while reading in a large line:\n%s'%(self,msg[0])
     742                except TypeError:
    741743                    pass
    742744            raise RuntimeError, '%s terminated unexpectedly while reading in a large line'%self
     745        except RuntimeError,msg:
     746            if self._quit_string() in line:
     747                if self._expect is None or not self._expect.isalive():
     748                    return ''
     749                raise
     750            if first_call==True and (self._expect is None or not self._expect.isalive()):
     751                try:
     752                    self._synchronize()
     753                    return self._post_process_from_file(self._eval_line_using_file(line, first_call=False))
     754                except TypeError:
     755                    pass
     756                except RuntimeError, msg:
     757                    raise RuntimeError, '%s terminated unexpectedly while reading in a large line'%self
     758            if "Input/output error" in msg[0]: # This occurs on non-linux machines
     759                raise RuntimeError, '%s terminated unexpectedly while reading in a large line'%self
     760            raise RuntimeError, '%s terminated unexpectedly while reading in a large line:\n%s'%(self,msg[0])
    743761        return self._post_process_from_file(s)
    744762
    745763    def _post_process_from_file(self, s):
     
    838856                    return ''
    839857               
    840858            except OSError, msg:
     859                if not E.isalive():
     860                    if first_call==True: # the subprocess might have crashed
     861                        try:
     862                            self._synchronize()
     863                            return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, first_call=False)
     864                        except (TypeError, RuntimeError):
     865                            pass
    841866                raise RuntimeError, "%s\nError evaluating %s in %s"%(msg, line, self)
    842867           
    843868            if len(line)>0:
  • sage/interfaces/gap.py

    diff --git a/sage/interfaces/gap.py b/sage/interfaces/gap.py
    a b  
    527527        """
    528528        #if line.find('\n') != -1:
    529529        #    raise ValueError, "line must not contain any newlines"
     530        E = None
    530531        try:
    531532            if self._expect is None:
    532533                self._start()
     
    561562            return out
    562563
    563564        except (RuntimeError,TypeError),message:
    564             if 'EOF' in message[0]:
     565            if 'EOF' in message[0] or E is None or not E.isalive():
    565566                print "** %s crashed or quit executing '%s' **"%(self, line)
    566567                print "Restarting %s and trying again"%self
    567568                self._start()
  • 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):
     374    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=False):
    375375        """
    376376        EXAMPLES::
    377377       
  • sage/interfaces/kash.py

    diff --git a/sage/interfaces/kash.py b/sage/interfaces/kash.py
    a b  
    506506
    507507    # Change the default for KASH, since eval using a file doesn't
    508508    # work except for setting variables.
    509     def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True):
     509    def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True, first_call=False):
    510510        return Expect._eval_line(self, line, allow_use_file=allow_use_file,
    511511                                 wait_for_prompt=wait_for_prompt)
    512512
  • 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):
     612    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=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):
     537    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, first_call=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):
     537    def _eval_line(self, line,  allow_use_file=True, wait_for_prompt=True, first_call=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  
    715715            raise KeyboardInterrupt, msg
    716716
    717717    def _eval_line(self, line, allow_use_file=False,
    718                    wait_for_prompt=True, reformat=True, error_check=True):
     718                   wait_for_prompt=True, reformat=True, error_check=True, first_call=False):
    719719        """
    720720        Return result of line evaluation.
    721721
  • sage/interfaces/mupad.py

    diff --git a/sage/interfaces/mupad.py b/sage/interfaces/mupad.py
    a b  
    238238        return AsciiArtString(s)
    239239
    240240    def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True,
    241                    need_output=True):
     241                   need_output=True, first_call=False):
    242242        """
    243243        EXAMPLES:
    244244            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):
     1099    def _eval_line(self, cmd, first_call=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