|
@@ -25,14 +25,14 @@ try:
|
|
from billiard.process import current_process
|
|
from billiard.process import current_process
|
|
except ImportError:
|
|
except ImportError:
|
|
current_process = None
|
|
current_process = None
|
|
|
|
+from billiard.compat import get_fdmax, close_open_fds
|
|
# fileno used to be in this module
|
|
# fileno used to be in this module
|
|
from kombu.utils import maybe_fileno
|
|
from kombu.utils import maybe_fileno
|
|
from kombu.utils.encoding import safe_str
|
|
from kombu.utils.encoding import safe_str
|
|
from contextlib import contextmanager
|
|
from contextlib import contextmanager
|
|
|
|
|
|
from .local import try_import
|
|
from .local import try_import
|
|
-from .five import items, range, reraise, string_t, zip_longest
|
|
|
|
-from .utils.functional import uniq
|
|
|
|
|
|
+from .five import items, reraise, string_t
|
|
|
|
|
|
_setproctitle = try_import('setproctitle')
|
|
_setproctitle = try_import('setproctitle')
|
|
resource = try_import('resource')
|
|
resource = try_import('resource')
|
|
@@ -110,26 +110,6 @@ class LockFailed(Exception):
|
|
"""Raised if a pidlock can't be acquired."""
|
|
"""Raised if a pidlock can't be acquired."""
|
|
|
|
|
|
|
|
|
|
-def get_fdmax(default=None):
|
|
|
|
- """Return the maximum number of open file descriptors
|
|
|
|
- on this system.
|
|
|
|
-
|
|
|
|
- :keyword default: Value returned if there's no file
|
|
|
|
- descriptor limit.
|
|
|
|
-
|
|
|
|
- """
|
|
|
|
- try:
|
|
|
|
- return os.sysconf('SC_OPEN_MAX')
|
|
|
|
- except:
|
|
|
|
- pass
|
|
|
|
- if resource is None: # Windows
|
|
|
|
- return default
|
|
|
|
- fdmax = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
|
|
|
- if fdmax == resource.RLIM_INFINITY:
|
|
|
|
- return default
|
|
|
|
- return fdmax
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class Pidfile(object):
|
|
class Pidfile(object):
|
|
"""Pidfile
|
|
"""Pidfile
|
|
|
|
|
|
@@ -268,30 +248,6 @@ def _create_pidlock(pidfile):
|
|
return pidlock
|
|
return pidlock
|
|
|
|
|
|
|
|
|
|
-if hasattr(os, 'closerange'):
|
|
|
|
-
|
|
|
|
- def close_open_fds(keep=None):
|
|
|
|
- # must make sure this is 0-inclusive (Issue #1882)
|
|
|
|
- keep = list(uniq(sorted(
|
|
|
|
- f for f in map(maybe_fileno, keep or []) if f is not None
|
|
|
|
- )))
|
|
|
|
- maxfd = get_fdmax(default=2048)
|
|
|
|
- kL, kH = iter([-1] + keep), iter(keep + [maxfd])
|
|
|
|
- for low, high in zip_longest(kL, kH):
|
|
|
|
- if low + 1 != high:
|
|
|
|
- os.closerange(low + 1, high)
|
|
|
|
-
|
|
|
|
-else:
|
|
|
|
-
|
|
|
|
- def close_open_fds(keep=None): # noqa
|
|
|
|
- keep = [maybe_fileno(f)
|
|
|
|
- for f in (keep or []) if maybe_fileno(f) is not None]
|
|
|
|
- for fd in reversed(range(get_fdmax(default=2048))):
|
|
|
|
- if fd not in keep:
|
|
|
|
- with ignore_errno(errno.EBADF):
|
|
|
|
- os.close(fd)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class DaemonContext(object):
|
|
class DaemonContext(object):
|
|
_is_open = False
|
|
_is_open = False
|
|
|
|
|