diff options
author | knownexus <phillip.smyth@codethink.co.uk> | 2018-08-30 11:45:53 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-09-27 15:22:09 +0100 |
commit | fcf37f9c02d38352ce4e03c0ad9c45a4c5ab5694 (patch) | |
tree | ab91b09743bbc561028e41a5ade8ef50266187fa | |
parent | ab1cb6724b115e3d6f4f17676d11339e3094e6dc (diff) | |
download | buildstream-fcf37f9c02d38352ce4e03c0ad9c45a4c5ab5694.tar.gz |
Added `set_resource_limits()` to platform
This has been moved from app.py
As it will have different functionality depending on platform
Once the Darwin (MacOS) platform is added
Removed `resource.setrlimit()` functionality from app.py
Added `resource.setrlimit()` functionality to platform.py as function
-rw-r--r-- | buildstream/_frontend/app.py | 8 | ||||
-rw-r--r-- | buildstream/_platform/platform.py | 15 |
2 files changed, 14 insertions, 9 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index a1afee478..f3dcd623b 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -115,14 +115,6 @@ class App(): else: self.colors = False - # Increase the soft limit for open file descriptors to the maximum. - # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox. - # Avoid hitting the limit too quickly. - limits = resource.getrlimit(resource.RLIMIT_NOFILE) - if limits[0] != limits[1]: - # Set soft limit to hard limit - resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1])) - # create() # # Should be used instead of the regular constructor. diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py index b37964986..d3878652e 100644 --- a/buildstream/_platform/platform.py +++ b/buildstream/_platform/platform.py @@ -19,6 +19,7 @@ import os import sys +import resource from .._exceptions import PlatformError, ImplError @@ -32,7 +33,7 @@ class Platform(): # sandbox factory as well as platform helpers. # def __init__(self): - pass + self.set_resource_limits() @classmethod def _create_instance(cls): @@ -84,3 +85,15 @@ class Platform(): def check_sandbox_config(self, config): raise ImplError("Platform {platform} does not implement check_sandbox_config()" .format(platform=type(self).__name__)) + + def set_resource_limits(self, soft_limit=None, hard_limit=None): + # Need to set resources for _frontend/app.py as this is dependent on the platform + # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox. + # Avoid hitting the limit too quickly. + limits = resource.getrlimit(resource.RLIMIT_NOFILE) + if limits[0] != limits[1]: + if soft_limit is None: + soft_limit = limits[1] + if hard_limit is None: + hard_limit = limits[1] + resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit)) |