• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.find_child_pids函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neutron.agent.linux.utils.find_child_pids函数的典型用法代码示例。如果您正苦于以下问题:Python find_child_pids函数的具体用法?Python find_child_pids怎么用?Python find_child_pids使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _get_pid_to_kill

 def _get_pid_to_kill(self):
     pid = self._process.pid
     # If root helper was used, two or more processes will be created:
     #
     #  - a root helper process (e.g. sudo myscript)
     #  - possibly a rootwrap script (e.g. neutron-rootwrap)
     #  - a child process (e.g. myscript)
     #
     # Killing the root helper process will leave the child process
     # running, re-parented to init, so the only way to ensure that both
     # die is to target the child process directly.
     if self.root_helper:
         try:
             pid = utils.find_child_pids(pid)[0]
         except IndexError:
             # Process is already dead
             return None
         while True:
             try:
                 # We shouldn't have more than one child per process
                 # so keep getting the children of the first one
                 pid = utils.find_child_pids(pid)[0]
             except IndexError:
                 # Last process in the tree, return it
                 break
     return pid
开发者ID:Taejun,项目名称:neutron,代码行数:26,代码来源:async_process.py


示例2: test_returns_list_of_child_process_ids_recursively

 def test_returns_list_of_child_process_ids_recursively(self):
     with mock.patch.object(utils, 'execute',
                            side_effect=[' 123 \n 185\n',
                                         ' 40 \n', '\n',
                                         '41\n', '\n']):
         actual = utils.find_child_pids(-1, True)
         self.assertEqual(actual, ['123', '185', '40', '41'])
开发者ID:openstack,项目名称:neutron,代码行数:7,代码来源:test_utils.py


示例3: _kill_listen_processes

def _kill_listen_processes(namespace, force=False):
    """Identify all listening processes within the given namespace.

    Then, for each one, find its top parent with same cmdline (in case this
    process forked) and issue a SIGTERM to all of them. If force is True,
    then a SIGKILL will be issued to all parents and all their children. Also,
    this function returns the number of listening processes.
    """
    pids = find_listen_pids_namespace(namespace)
    pids_to_kill = {utils.find_fork_top_parent(pid) for pid in pids}
    kill_signal = signal.SIGTERM
    if force:
        kill_signal = signal.SIGKILL
        children = [utils.find_child_pids(pid, True) for pid in pids_to_kill]
        pids_to_kill.update(itertools.chain.from_iterable(children))

    for pid in pids_to_kill:
        # Throw a warning since this particular cleanup may need a specific
        # implementation in the right module. Ideally, netns_cleanup wouldn't
        # kill any processes as the responsible module should've killed them
        # before cleaning up the namespace
        LOG.warning("Killing (%(signal)d) [%(pid)s] %(cmdline)s",
                    {'signal': kill_signal,
                     'pid': pid,
                     'cmdline': ' '.join(utils.get_cmdline_from_pid(pid))[:80]
                     })
        try:
            utils.kill_process(pid, kill_signal, run_as_root=True)
        except Exception as ex:
            LOG.error('An error occurred while killing '
                      '[%(pid)s]: %(msg)s', {'pid': pid, 'msg': ex})
    return len(pids)
开发者ID:igordcard,项目名称:neutron,代码行数:32,代码来源:netns_cleanup.py


示例4: _get_pid_to_kill

 def _get_pid_to_kill(self):
     pid = self._process.pid
     # If root helper was used, two processes will be created:
     #
     #  - a root helper process (e.g. sudo myscript)
     #  - a child process (e.g. myscript)
     #
     # Killing the root helper process will leave the child process
     # as a zombie, so the only way to ensure that both die is to
     # target the child process directly.
     if self.root_helper:
         pids = utils.find_child_pids(pid)
         if pids:
             # The root helper will only ever launch a single child.
             pid = pids[0]
         else:
             # Process is already dead.
             pid = None
     return pid
开发者ID:JoeMido,项目名称:neutron,代码行数:19,代码来源:async_process.py


示例5: test_raises_unknown_exception

 def test_raises_unknown_exception(self):
     with testtools.ExpectedException(RuntimeError):
         with mock.patch.object(utils, 'execute',
                                side_effect=RuntimeError()):
             utils.find_child_pids(-1)
开发者ID:bradleyjones,项目名称:neutron,代码行数:5,代码来源:test_utils.py


示例6: test_returns_list_of_child_process_ids_for_good_ouput

 def test_returns_list_of_child_process_ids_for_good_ouput(self):
     with mock.patch.object(utils, 'execute', return_value=' 123 \n 185\n'):
         self.assertEqual(utils.find_child_pids(-1), ['123', '185'])
开发者ID:bradleyjones,项目名称:neutron,代码行数:3,代码来源:test_utils.py


示例7: test_returns_empty_list_for_no_output

 def test_returns_empty_list_for_no_output(self):
     with mock.patch.object(utils, 'execute', return_value=''):
         self.assertEqual(utils.find_child_pids(-1), [])
开发者ID:bradleyjones,项目名称:neutron,代码行数:3,代码来源:test_utils.py


示例8: test_returns_empty_list_for_exit_code_1

 def test_returns_empty_list_for_exit_code_1(self):
     with mock.patch.object(utils, 'execute',
                            side_effect=RuntimeError('Exit code: 1')):
         self.assertEqual(utils.find_child_pids(-1), [])
开发者ID:bradleyjones,项目名称:neutron,代码行数:4,代码来源:test_utils.py


示例9: test_returns_empty_list_for_exit_code_1

 def test_returns_empty_list_for_exit_code_1(self):
     with mock.patch.object(utils, 'execute',
                            side_effect=exceptions.ProcessExecutionError(
                                '', returncode=1)):
         self.assertEqual([], utils.find_child_pids(-1))
开发者ID:openstack,项目名称:neutron,代码行数:5,代码来源:test_utils.py


示例10: test_returns_empty_list_for_no_output

 def test_returns_empty_list_for_no_output(self):
     with mock.patch.object(utils, "execute", return_value=""):
         self.assertEqual([], utils.find_child_pids(-1))
开发者ID:openstack,项目名称:neutron,代码行数:3,代码来源:test_utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_interface_mac函数代码示例发布时间:2022-05-27
下一篇:
Python utils.execute函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap