Skip to content

polymake interface: Bug in interrupt handling - expect_list #22702

@mkoeppe

Description

@mkoeppe

Following up on #22452 (Create a Polymake pexpect interface):

In polymake.py, Polymake._keyboard_interrupt passes a bad first argument in the line

i = self._expect.expect_list(self._prompt, timeout=1)

This leads to:

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/sage/interfaces/polymake.pyc in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed, **kwds)
    919                         except (TypeError, RuntimeError):
    920                             pass
--> 921                         return self._eval_line(line,allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt, restart_if_needed=False, **kwds)
    922                 raise_(RuntimeError, "%s\nError evaluating %s in %s"%(msg, line, self), sys.exc_info()[2])
    923 

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/sage/interfaces/polymake.pyc in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed, **kwds)
   1052                 out = ''
   1053         except KeyboardInterrupt:
-> 1054             self._keyboard_interrupt()
   1055             raise KeyboardInterrupt("Ctrl-c pressed while running %s"%self)
   1056         for w in p_warnings:

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/sage/interfaces/polymake.pyc in _keyboard_interrupt(self)
    446                 raise pexpect.ExceptionPexpect("THIS IS A BUG -- PLEASE REPORT. This should never happen.\n" + msg)
    447             sleep(0.1)
--> 448             i = self._expect.expect_list(self._prompt, timeout=1)
    449             if i==0:
    450                 break

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/pexpect/spawnbase.pyc in expect_list(self, pattern_list, timeout, searchwindowsize, async)
    343             return expect_async(exp, timeout)
    344         else:
--> 345             return exp.expect_loop(timeout)
    346 
    347     def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1,

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/pexpect/expect.pyc in expect_loop(self, timeout)
     89             spawn.buffer = spawn.string_type()  # Treat buffer as new data
     90             while True:
---> 91                 idx = self.new_data(incoming)
     92                 # Keep reading until exception or return.
     93                 if idx is not None:

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/pexpect/expect.pyc in new_data(self, data)
     17         incoming = spawn.buffer + data
     18         freshlen = len(data)
---> 19         index = searcher.search(incoming, freshlen, self.searchwindowsize)
     20         if index >= 0:
     21             spawn.buffer = incoming[searcher.end:]

/Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/pexpect/expect.pyc in search(self, buffer, freshlen, searchwindowsize)
    285             searchstart = max(0, len(buffer) - searchwindowsize)
    286         for index, s in self._searches:
--> 287             match = s.search(buffer, searchstart)
    288             if match is None:
    289                 continue

AttributeError: 'str' object has no attribute 'search'
sage: 
sage: %debug
> /Users/mkoeppe/s/sage/sage-rebasing/another-local-sans-autotools/lib/python2.7/site-packages/pexpect/expect.py(287)search()
    285             searchstart = max(0, len(buffer) - searchwindowsize)
    286         for index, s in self._searches:
--> 287             match = s.search(buffer, searchstart)
    288             if match is None:
    289                 continue

ipdb> print s
p
ipdb> print type(s)
<type 'str'>

I do not know how to reproduce this consistently. It involves pressing C-c at the right moment.

See also: #22710: Meta-ticket: polymake

Depends on #22452

CC: @simon-king-jena

Component: interfaces

Keywords: polymake

Issue created by migration from https://trac.sagemath.org/ticket/22702

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions