Skip to content
Snippets Groups Projects
Commit 481b0ead authored by knownexus's avatar knownexus
Browse files

Moved `resource.getrlimit()`

Removed `resource.getrlimit()` functionality from app.py
Added `resource.getrlimit()` functionality to platform.py as function
Called new function from __init__.py of linux.py and unix.py
parent 6a0cdedf
No related branches found
No related tags found
No related merge requests found
......@@ -116,14 +116,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.
......
......@@ -52,7 +52,6 @@ class Linux(Platform):
# Private Methods #
################################################
def _check_user_ns_available(self, context):
# Here, lets check if bwrap is able to create user namespaces,
# issue a warning if it's not available, and save the state
# locally so that we can inform the sandbox to not try it
......
......@@ -37,6 +37,7 @@ class Platform():
#
def __init__(self, context):
self.context = context
self.set_resources()
@classmethod
def create_instance(cls, *args, **kwargs):
......@@ -92,3 +93,15 @@ class Platform():
def create_sandbox(self, *args, **kwargs):
raise ImplError("Platform {platform} does not implement create_sandbox()"
.format(platform=type(self).__name__))
def set_resources(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))
......@@ -18,6 +18,7 @@
# Tristan Maat <tristan.maat@codethink.co.uk>
import os
import resource
from .._artifactcache.cascache import CASCache
from .._exceptions import PlatformError
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment