subprocess.CalledProcessError:返回非零退出状态 0

Posted

技术标签:

【中文标题】subprocess.CalledProcessError:返回非零退出状态 0【英文标题】:subprocess.CalledProcessError: returned non-zero exit status 0 【发布时间】:2016-08-09 16:25:17 【问题描述】:

这个自相矛盾的错误是什么意思?

subprocess.CalledProcessError: 命令 '/home/travis/build/fritzo/pomagma/build/debug/src/cartographer/cartographer' 返回非零退出状态 0

当我启动一个子进程时会发生这种情况,然后告诉该子进程通过 zmq 套接字干净地退出。看来在zmq轮询时,进程干净退出(退出代码0),然后引发此错误。

这是整个回溯(来自travis log):

Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/bin/pomagma.make", line 9, in <module>
    load_entry_point('pomagma==0.2.8', 'console_scripts', 'pomagma.make')()
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/parsable.py", line 181, in dispatch
    dispatch(argv)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/parsable.py", line 129, in dispatch
    parser(*args, **kwargs)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/parsable.py", line 64, in parser
    fun(*typed_args, **typed_kwargs)
  File "/home/travis/build/fritzo/pomagma/pomagma/make.py", line 130, in test_atlas
    _test_atlas(theory)
  File "/home/travis/build/fritzo/pomagma/pomagma/make.py", line 59, in _test_atlas
    assert actual_size == expected_size
  File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/home/travis/build/fritzo/pomagma/pomagma/cartographer/__init__.py", line 14, in load
    client.stop()
  File "/home/travis/build/fritzo/pomagma/pomagma/cartographer/client.py", line 207, in stop
    self._call(request)
  File "/home/travis/build/fritzo/pomagma/pomagma/cartographer/client.py", line 35, in _call
    self._poll_callback()
  File "/home/travis/build/fritzo/pomagma/pomagma/cartographer/server.py", line 66, in check
    self.log_error()
  File "/home/travis/build/fritzo/pomagma/pomagma/cartographer/server.py", line 73, in log_error
    raise CalledProcessError(self._proc.poll(), BINARY)
subprocess.CalledProcessError: Command '/home/travis/build/fritzo/pomagma/build/debug/src/cartographer/cartographer' returned non-zero exit status 0

【问题讨论】:

【参考方案1】:

根据文档,如果您的子进程返回非零,那么它将引发该异常。这也是 Linux 中的标准约定。 https://docs.python.org/2/library/subprocess.html

尝试包含您的子流程客户端代码 尝试: <...> 抓住: <...> 最后: sys.exit(0)

【讨论】:

但是该过程没有返回非零:它返回0。这是怎么回事?

以上是关于subprocess.CalledProcessError:返回非零退出状态 0的主要内容,如果未能解决你的问题,请参考以下文章