当前位置: 首页>>代码示例>>Python>>正文


Python Popen.kill方法代码示例

本文整理汇总了Python中solaris_install.Popen.kill方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.kill方法的具体用法?Python Popen.kill怎么用?Python Popen.kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solaris_install.Popen的用法示例。


在下文中一共展示了Popen.kill方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_logging_no_hang

# 需要导入模块: from solaris_install import Popen [as 别名]
# 或者: from solaris_install.Popen import kill [as 别名]
    def test_logging_no_hang(self):
        '''Try to ensure Popen.check_call doesn't hang when trying to do
        logging'''

        # To ensure the logger keyword arg is implemented in a way that
        # doesn't cause hangs, and since the use of logger causes blocking
        # behavior, spawn a non-blocking subprocess that spawns a blocking
        # subprocess. If the non-blocking subprocess doesn't complete
        # in a reasonable amount of time, kill both and fail
        cmd = [sys.executable, "-c",
               "from solaris_install import Popen; import logging; "
               "Popen.check_call(['/usr/bin/pkg', 'foo'], "
               "logger=logging.getLogger())"]

        popen = Popen(cmd, stdout=Popen.DEVNULL, stderr=Popen.DEVNULL)
        for wait_count in xrange(15):
            # If it's not done nearly instantly, something is wrong.
            # However, give the benefit of the doubt by waiting up to
            # 5 seconds for completion
            if popen.poll() is not None:
                break
            else:
                time.sleep(0.5)
        else:
            popen.kill()
            self.fail("subprocess hung while attempting logging")
开发者ID:PluribusNetworks,项目名称:pluribus_userland,代码行数:28,代码来源:test_install_common.py

示例2: test_devnull

# 需要导入模块: from solaris_install import Popen [as 别名]
# 或者: from solaris_install.Popen import kill [as 别名]
    def test_devnull(self):
        '''Test using Popen.DEVNULL for stdin'''
        popen = Popen(["/usr/bin/cat"], stdin=Popen.DEVNULL, stdout=Popen.PIPE)
        # Use PIPE for stdout as, for a failure case, the subprocess call
        # could hang indefinitely, so we can't block on it

        for wait_count in xrange(10):
            # If it's not done nearly instantly, something is wrong.
            # However, give the benefit of the doubt by waiting up to
            # 5 seconds for completion
            if popen.poll() is not None:
                break
            else:
                time.sleep(0.5)
        else:
            popen.kill()
            self.fail("stdin=Popen.DEVNULL did not work")

        stdout = popen.communicate()[0]
        self.assertEqual("", stdout)
开发者ID:PluribusNetworks,项目名称:pluribus_userland,代码行数:22,代码来源:test_install_common.py


注:本文中的solaris_install.Popen.kill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。