當前位置: 首頁>>代碼示例>>Python>>正文


Python resource.RLIMIT_DATA屬性代碼示例

本文整理匯總了Python中resource.RLIMIT_DATA屬性的典型用法代碼示例。如果您正苦於以下問題:Python resource.RLIMIT_DATA屬性的具體用法?Python resource.RLIMIT_DATA怎麽用?Python resource.RLIMIT_DATA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在resource的用法示例。


在下文中一共展示了resource.RLIMIT_DATA屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: report_resource_limits

# 需要導入模塊: import resource [as 別名]
# 或者: from resource import RLIMIT_DATA [as 別名]
def report_resource_limits(logger: logging.Logger) -> None:
    resources = [
        ('CPU time (seconds)', resource.RLIMIT_CPU),
        ('Heap size (bytes)', resource.RLIMIT_DATA),
        ('Num. process', resource.RLIMIT_NPROC),
        ('Num. files', resource.RLIMIT_NOFILE),
        ('Address space', resource.RLIMIT_AS),
        ('Locked address space', resource.RLIMIT_MEMLOCK)
    ]
    resource_limits = [
        (name, resource.getrlimit(res)) for (name, res) in resources
    ]
    resource_s = '\n'.join([
        '* {}: {}'.format(res, lim) for (res, lim) in resource_limits
    ])
    logger.info("resource limits:\n%s", indent(resource_s, 2)) 
開發者ID:squaresLab,項目名稱:BugZoo,代碼行數:18,代碼來源:util.py

示例2: make_memsafe

# 需要導入模塊: import resource [as 別名]
# 或者: from resource import RLIMIT_DATA [as 別名]
def make_memsafe():
    if sys.platform.startswith('linux'):
        import resource
        import psutil
        for rsrc in (resource.RLIMIT_AS, resource.RLIMIT_DATA):
            freemem = psutil.virtual_memory().free
            hard = int(round(freemem *.8))
            soft = hard
            resource.setrlimit(rsrc, (soft, hard)) #limit to 80% of available memory 
開發者ID:danielnyga,項目名稱:pracmln,代碼行數:11,代碼來源:multicore.py

示例3: test_data_size

# 需要導入模塊: import resource [as 別名]
# 或者: from resource import RLIMIT_DATA [as 別名]
def test_data_size(self):
        max_memory = self.memory_limit(resource.RLIMIT_DATA)
        prlimit = processutils.ProcessLimits(data_size=max_memory)
        self.check_limit(prlimit, 'RLIMIT_DATA', max_memory) 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:6,代碼來源:test_processutils.py

示例4: setProcessLimits

# 需要導入模塊: import resource [as 別名]
# 或者: from resource import RLIMIT_DATA [as 別名]
def setProcessLimits(x):
        # This is called after fork and before exec. Any messages
        # printed here will look like the program that we are calling
        # printed them out.

        #print("pre switch user")
        if switchUser:
            if os.geteuid() != 0:
                print("We can't switch to a different user if this script is not run as root.")
                exit(1)
            # If we are supposed to switch to a different user account to do the grading
            if os.geteuid() == 0:
                os.setreuid(autograderUid,autograderUid)
            if os.geteuid() == 0:
                print("Still root after trying to switch to autograder user?")
                exit(1)
        else:
            # If we are not switching to a different user, make sure that we don't run as root.
            if os.geteuid() == 0:
                print("Halting. Do not run submitted programs as root.")
                exit(1)
                
        #print("post switch user")
        
        #print("Preexec start")
        if os.setpgrp() == -1:  # put all processes in the same process group so we can kill it and all children it creates.
            print("Failed to set process group!")
        #print("Preexec middle")

        def limitHelper(limitType, limit):
            # limit is a string referring to a previously set environment variable.
            if limit in os.environ:
                limit = int(os.environ[limit])
                (soft, hard) = resource.getrlimit(limitType)
                #print("soft %d, hard %d, requested %d\n" % (soft, hard, limit))
                if hard > 0 and limit > hard:
                    limit = hard
                resource.setrlimit(limitType, (limit, limit))

        limitHelper(resource.RLIMIT_NPROC, "ULIMIT_NPROC")
        limitHelper(resource.RLIMIT_AS, "ULIMIT_AS")
        limitHelper(resource.RLIMIT_DATA, "ULIMIT_DATA") 
開發者ID:skuhl,項目名稱:autograder,代碼行數:44,代碼來源:autograder.py


注:本文中的resource.RLIMIT_DATA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。