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


Python Process.get_open_files方法代码示例

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


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

示例1: testFDTDServiceOpenFiles

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_open_files [as 别名]
def testFDTDServiceOpenFiles():
    """
    #41 - Too many open files (fdtd side)

    """
    hostName = os.uname()[1]
    f = getTempFile(functionalFDTDConfiguration)
    inputOption = "--config=%s" % f.name
    conf = ConfigFDTD(inputOption.split())
    conf.sanitize()
    testName = inspect.stack()[0][3]
    logger = Logger(name=testName, logFile="/tmp/fdtdtest-%s.log" % testName, level=logging.DEBUG)
    apMon = None
    fdtd = FDTD(conf, apMon, logger)

    proc = Process(os.getpid())
    initStateNumOpenFiles = len(proc.get_open_files())

    for testAction in [TestAction("fakeSrc", "fakeDst") for i in range(3)]:
        r = fdtd.service.service(testAction)
        logger.debug("Result: %s" % r)
        assert r.status == 0

    # after TestAction, there should not be left behind any open files
    numOpenFilesNow = len(proc.get_open_files())
    assert initStateNumOpenFiles == numOpenFilesNow

    # test on ReceivingServerAction - it's action after which the
    # separate logger is not closed, test the number of open files went +1,
    # send CleanupProcessesAction and shall again remain
    # initStateNumOpenFiles send appropriate TestAction first (like in real)
    serverId = "server-id"
    testAction = TestAction(hostName, hostName)
    testAction.id = serverId
    r = fdtd.service.service(testAction)
    assert r.status == 0
    options = dict(gridUserDest="someuserDest", clientIP=os.uname()[1], destFiles=[])
    recvServerAction = ReceivingServerAction(testAction.id, options)
    r = fdtd.service.service(recvServerAction)
    print(r.msg)
    assert r.status == 0
    numOpenFilesNow = len(proc.get_open_files())
    # there should be only 1 extra opened file now
    assert initStateNumOpenFiles == numOpenFilesNow - 1
    cleanupAction = CleanupProcessesAction(serverId, timeout=2)
    r = fdtd.service.service(cleanupAction)
    print(r.msg)
    assert r.status == 0
    numOpenFilesNow = len(proc.get_open_files())
    assert initStateNumOpenFiles == numOpenFilesNow

    fdtd.shutdown()
    fdtd.pyroDaemon.closedown()
    logger.close()
开发者ID:juztas,项目名称:fdtcp,代码行数:56,代码来源:test_fdtd.py

示例2: getOpenFilesList

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_open_files [as 别名]
def getOpenFilesList(offset=4):
    """
    Returns all currently open files.
    Problem: #41 - Too many open files (fdtd side)
    """
    myPid = os.getpid()
    proc = Process(myPid)
    files = proc.get_open_files()
    filesStr = "\n".join(["%s%s (fd=%s)" % (offset * ' ', f.path, f.fd)
                          for f in files])
    numFiles = len(files)
    return numFiles, filesStr
开发者ID:juztas,项目名称:fdtcp,代码行数:14,代码来源:utils.py


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