0

我正在尝试导入八度,但它超时;并非总是如此,但大多数时候。有什么解决办法吗?如何更改导入命令的超时限制?在我的脚本中,我只有以下行:

from oct2py import octave

我收到以下错误:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from oct2py import octave
  File "/usr/local/lib/python2.7/site-packages/oct2py/__init__.py", line 38, in <module>
    octave = Oct2Py()
  File "/usr/local/lib/python2.7/site-packages/oct2py/core.py", line 76, in __init__
    self.restart()
  File "/usr/local/lib/python2.7/site-packages/oct2py/core.py", line 518, in restart
    logger=self.logger)
  File "/usr/local/lib/python2.7/site-packages/octave_kernel/kernel.py", line 173, in __init__
    self.repl = self._create_repl()
  File "/usr/local/lib/python2.7/site-packages/octave_kernel/kernel.py", line 391, in _create_repl
    force_prompt_on_continuation=True)
  File "/usr/local/lib/python2.7/site-packages/metakernel/replwrap.py", line 97, in __init__
    continuation_prompt_regex))
  File "/usr/local/lib/python2.7/site-packages/metakernel/replwrap.py", line 119, in set_prompt
    self.child.expect(prompt_regex)
  File "/usr/local/lib/python2.7/site-packages/pexpect/spawnbase.py", line 341, in expect
    timeout, searchwindowsize, async_)
  File "/usr/local/lib/python2.7/site-packages/pexpect/spawnbase.py", line 369, in expect_list
    return exp.expect_loop(timeout)
  File "/usr/local/lib/python2.7/site-packages/pexpect/expect.py", line 119, in expect_loop
    return self.timeout(e)
  File "/usr/local/lib/python2.7/site-packages/pexpect/expect.py", line 82, in timeout
    raise TIMEOUT(msg)
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7fbe43d8f910>
command: /usr/bin/octave-cli
args: ['/usr/bin/octave-cli', '--interactive', '--quiet', '--no-init-file']
buffer (last 100 chars): u''

after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 2507
child_fd: 6
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile(u'octave.*>')
4

1 回答 1

1

正如 OP 所提到的,该异常来自 oct2py,MonkeyPatching 将是解决此问题的方法之一。

要尝试修复,您可以转到以下代码行并添加timeout=None为参数

在您的本地文件系统中,/usr/local/lib/python2.7/site-packages/metakernel/replwrap.py第 119 行。

此处相同来源的 Github 链接

看起来您正在使用 pexpect 来提高超时。

根据文档形式 pexpect,您可以控制超时行为 -

child.expect(pexpect.EOF, timeout=None)
于 2020-04-06T07:55:39.307 回答