예제 #1
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)
        os.umask(old_umask)

        # change the owner and group of the file if the worker will run as
        # a different user or group, so that the worker can modify the file
        if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
            util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            # In Python 3.8, open() emits RuntimeWarning if buffering=1 for binary mode.
            # Because we never write to this file, pass 0 to switch buffering off.
            self._tmp = os.fdopen(fd, 'w+b', 0)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #2
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        # 如何你的应用程序需要一个临时文件来存储数据
        # 但不需要同其他程序共享,那么用TemporaryFile函数创建临时文件是最好的选择。
        # 其他的应用程序是无法找到或打开这个文件的,
        # 因为它并没有引用文件系统表。用这个函数创建的临时文件,关闭后会自动删除。
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #3
0
    def unlock(self):
        if not self.locked():
            return

        if _unlock(self._lockfile.fileno()):
            self._lockfile.close()
            util.unlink(self.fname)
            self._lockfile = None
            self._locked = False
예제 #4
0
    def __init__(self, cfg):
        fd, name = tempfile.mkstemp(prefix="wgunicorn-")

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #5
0
    def __init__(self, cfg):
        fd, name = tempfile.mkstemp(prefix="wgunicorn-")

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #6
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #8
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)
        os.umask(old_umask)

        # change the owner and group of the file if the worker will run as
        # a different user or group, so that the worker can modify the file
        if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
            util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
예제 #9
0
def __worker_tmp_init__(self, cfg):
    old_umask = os.umask(cfg.umask)
    fdir = cfg.worker_tmp_dir
    if fdir and not os.path.isdir(fdir):
        raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
    fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

    # avoid os.chown when running via snap with strict confinement
    # ref : https://github.com/benoitc/gunicorn/issues/2059
    if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
    os.umask(old_umask)

    # unlink the file so we don't leak tempory files
    try:
        if not IS_CYGWIN:
            util.unlink(name)
        self._tmp = os.fdopen(fd, 'w+b', 1)
    except:
        os.close(fd)
        raise

    self.spinner = 0