diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-08-27 22:53:59 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-08-27 22:53:59 (GMT) |
commit | daf455554bc21b6b5df0a016ab5fa639d36cc595 (patch) | |
tree | 216f52f9f6d9aed0406b2ce2574e5a02aa93e327 /Lib/multiprocessing | |
parent | 46e1ce214b5711e8dae63a1b5a0a7aafb371baf0 (diff) | |
download | cpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.zip cpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.tar.gz cpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.tar.bz2 |
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(),
os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/connection.py | 6 | ||||
-rw-r--r-- | Lib/multiprocessing/forkserver.py | 4 | ||||
-rw-r--r-- | Lib/multiprocessing/popen_fork.py | 2 | ||||
-rw-r--r-- | Lib/multiprocessing/popen_spawn_posix.py | 4 | ||||
-rw-r--r-- | Lib/multiprocessing/semaphore_tracker.py | 2 | ||||
-rw-r--r-- | Lib/multiprocessing/util.py | 8 |
6 files changed, 15 insertions, 11 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index 443fa7e..9fbe46d 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -509,7 +509,7 @@ if sys.platform != 'win32': c1 = Connection(s1.detach()) c2 = Connection(s2.detach()) else: - fd1, fd2 = util.pipe() + fd1, fd2 = os.pipe() c1 = Connection(fd1, writable=False) c2 = Connection(fd2, readable=False) @@ -536,7 +536,9 @@ else: _winapi.FILE_FLAG_FIRST_PIPE_INSTANCE, _winapi.PIPE_TYPE_MESSAGE | _winapi.PIPE_READMODE_MESSAGE | _winapi.PIPE_WAIT, - 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL + 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, + # default security descriptor: the handle cannot be inherited + _winapi.NULL ) h2 = _winapi.CreateFile( address, access, 0, _winapi.NULL, _winapi.OPEN_EXISTING, diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py index 208bd4e..11df382 100644 --- a/Lib/multiprocessing/forkserver.py +++ b/Lib/multiprocessing/forkserver.py @@ -60,8 +60,8 @@ def connect_to_new_process(fds): raise ValueError('too many fds') with socket.socket(socket.AF_UNIX) as client: client.connect(_forkserver_address) - parent_r, child_w = util.pipe() - child_r, parent_w = util.pipe() + parent_r, child_w = os.pipe() + child_r, parent_w = os.pipe() allfds = [child_r, child_w, _forkserver_alive_fd, semaphore_tracker._semaphore_tracker_fd] allfds += fds diff --git a/Lib/multiprocessing/popen_fork.py b/Lib/multiprocessing/popen_fork.py index fd25ddc..c9f3aae 100644 --- a/Lib/multiprocessing/popen_fork.py +++ b/Lib/multiprocessing/popen_fork.py @@ -66,7 +66,7 @@ class Popen(object): def _launch(self, process_obj): code = 1 - parent_r, child_w = util.pipe() + parent_r, child_w = os.pipe() self.pid = os.fork() if self.pid == 0: try: diff --git a/Lib/multiprocessing/popen_spawn_posix.py b/Lib/multiprocessing/popen_spawn_posix.py index e67915d..751bf22 100644 --- a/Lib/multiprocessing/popen_spawn_posix.py +++ b/Lib/multiprocessing/popen_spawn_posix.py @@ -54,8 +54,8 @@ class Popen(popen_fork.Popen): parent_r = child_w = child_r = parent_w = None try: - parent_r, child_w = util.pipe() - child_r, parent_w = util.pipe() + parent_r, child_w = os.pipe() + child_r, parent_w = os.pipe() cmd = spawn.get_command_line(tracker_fd=tracker_fd, pipe_handle=child_r) self._fds.extend([child_r, child_w]) diff --git a/Lib/multiprocessing/semaphore_tracker.py b/Lib/multiprocessing/semaphore_tracker.py index 99a0dd4..6c9e4a5 100644 --- a/Lib/multiprocessing/semaphore_tracker.py +++ b/Lib/multiprocessing/semaphore_tracker.py @@ -45,7 +45,7 @@ def ensure_running(): except Exception: pass cmd = 'from multiprocessing.semaphore_tracker import main; main(%d)' - r, w = util.pipe() + r, w = os.pipe() try: fds_to_pass.append(r) # process will out live us, so no need to wait on pid diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py index d9e4799..ac8e913 100644 --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -365,7 +365,7 @@ def spawnv_passfds(path, args, passfds): if flag & fcntl.FD_CLOEXEC: fcntl.fcntl(fd, fcntl.F_SETFD, flag & ~fcntl.FD_CLOEXEC) tmp.append((fd, flag)) - errpipe_read, errpipe_write = _posixsubprocess.cloexec_pipe() + errpipe_read, errpipe_write = os.pipe() try: return _posixsubprocess.fork_exec( args, [os.fsencode(path)], True, passfds, None, None, @@ -381,7 +381,9 @@ def spawnv_passfds(path, args, passfds): # # Return pipe with CLOEXEC set on fds # +# Deprecated: os.pipe() creates non-inheritable file descriptors +# since Python 3.4 +# def pipe(): - import _posixsubprocess - return _posixsubprocess.cloexec_pipe() + return os.pipe() |