Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def close_open_fds(keep=None):
     keep = [maybe_fileno(f)
             for f in uniq(sorted(keep or []))
             if maybe_fileno(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)
Ejemplo n.º 4
0
 def close_open_fds(keep=None):
     keep = list(uniq(sorted(filter(None, (
         maybe_fileno(f) for f in keep or []
     )))))
     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)
Ejemplo n.º 5
0
    def open(self):
        if not self._is_open:
            if not self.fake:
                self._detach()

            os.chdir(self.workdir)
            os.umask(self.umask)

            if self.after_chdir:
                self.after_chdir()

            close_open_fds(self.stdfds)
            for fd in self.stdfds:
                self.redirect_to_null(maybe_fileno(fd))

            self._is_open = True
Ejemplo n.º 6
0
    def open(self):
        if not self._is_open:
            if not self.fake:
                self._detach()

            os.chdir(self.workdir)
            os.umask(self.umask)

            if self.after_chdir:
                self.after_chdir()

            close_open_fds(self.stdfds)
            for fd in self.stdfds:
                self.redirect_to_null(maybe_fileno(fd))

            self._is_open = True
Ejemplo n.º 7
0
    def open(self):
        if not self._is_open:
            if not self.fake:
                self._detach()

            os.chdir(self.workdir)
            os.umask(self.umask)

            if self.after_chdir:
                self.after_chdir()

            if not self.fake:
                close_open_fds(self.stdfds)
                for fd in self.stdfds:
                    self.redirect_to_null(maybe_fileno(fd))
                if self.after_forkers and mputil is not None:
                    mputil._run_after_forkers()

            self._is_open = True
Ejemplo n.º 8
0
    def open(self):
        if not self._is_open:
            if not self.fake:
                self._detach()

            os.chdir(self.workdir)
            if self.umask is not None:
                os.umask(self.umask)

            if self.after_chdir:
                self.after_chdir()

            if not self.fake:
                # We need to keep /dev/urandom from closing because
                # shelve needs it, and Beat needs shelve to start.
                keep = list(self.stdfds) + fd_by_path(['/dev/urandom'])
                close_open_fds(keep)
                for fd in self.stdfds:
                    self.redirect_to_null(maybe_fileno(fd))

            self._is_open = True
Ejemplo n.º 9
0
    def open(self):
        if not self._is_open:
            if not self.fake:
                self._detach()

            os.chdir(self.workdir)
            if self.umask is not None:
                os.umask(self.umask)

            if self.after_chdir:
                self.after_chdir()

            if not self.fake:
                # We need to keep /dev/urandom from closing because
                # shelve needs it, and Beat needs shelve to start.
                keep = list(self.stdfds) + fd_by_path(['/dev/urandom'])
                close_open_fds(keep)
                for fd in self.stdfds:
                    self.redirect_to_null(maybe_fileno(fd))

            self._is_open = True
Ejemplo n.º 10
0
def close_open_fds(keep=None):
    keep = [maybe_fileno(f) for f in keep if maybe_fileno(f)] if keep else []
    for fd in reversed(range(get_fdmax(default=2048))):
        if fd not in keep:
            with ignore_errno(errno.EBADF):
                os.close(fd)
Ejemplo n.º 11
0
def close_open_fds(keep=None):
    keep = [maybe_fileno(f) for f in keep if maybe_fileno(f)] if keep else []
    for fd in reversed(range(get_fdmax(default=2048))):
        if fd not in keep:
            with ignore_errno(errno.EBADF):
                os.close(fd)
Ejemplo n.º 12
0
 def close_open_fds(keep):
     keep = [maybe_fileno(f)
             for f in uniq(sorted((keep or [])))
             if maybe_fileno(f) is not None]
     for low, high in ranges(keep, get_fdmax(default=2048)):
         os.closerange(low, high)
Ejemplo n.º 13
0
 def test_maybe_fileno(self):
     self.assertEqual(utils.maybe_fileno(3), 3)
     f = Mock(name='file')
     self.assertIs(utils.maybe_fileno(f), f.fileno())
     f.fileno.side_effect = ValueError()
     self.assertIsNone(utils.maybe_fileno(f))
Ejemplo n.º 14
0
 def test_maybe_fileno(self):
     self.assertEqual(utils.maybe_fileno(3), 3)
     f = Mock(name='file')
     self.assertIs(utils.maybe_fileno(f), f.fileno())
     f.fileno.side_effect = ValueError()
     self.assertIsNone(utils.maybe_fileno(f))