Execute program using os.posix_spawn().
(self, args, executable, env, restore_signals, close_fds,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite)
| 1783 | |
| 1784 | |
| 1785 | def _posix_spawn(self, args, executable, env, restore_signals, close_fds, |
| 1786 | p2cread, p2cwrite, |
| 1787 | c2pread, c2pwrite, |
| 1788 | errread, errwrite): |
| 1789 | """Execute program using os.posix_spawn().""" |
| 1790 | kwargs = {} |
| 1791 | if restore_signals: |
| 1792 | # See _Py_RestoreSignals() in Python/pylifecycle.c |
| 1793 | sigset = [] |
| 1794 | for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'): |
| 1795 | signum = getattr(signal, signame, None) |
| 1796 | if signum is not None: |
| 1797 | sigset.append(signum) |
| 1798 | kwargs['setsigdef'] = sigset |
| 1799 | |
| 1800 | file_actions = [] |
| 1801 | for fd in (p2cwrite, c2pread, errread): |
| 1802 | if fd != -1: |
| 1803 | file_actions.append((os.POSIX_SPAWN_CLOSE, fd)) |
| 1804 | for fd, fd2 in ( |
| 1805 | (p2cread, 0), |
| 1806 | (c2pwrite, 1), |
| 1807 | (errwrite, 2), |
| 1808 | ): |
| 1809 | if fd != -1: |
| 1810 | file_actions.append((os.POSIX_SPAWN_DUP2, fd, fd2)) |
| 1811 | |
| 1812 | if close_fds: |
| 1813 | file_actions.append((os.POSIX_SPAWN_CLOSEFROM, 3)) |
| 1814 | |
| 1815 | if file_actions: |
| 1816 | kwargs['file_actions'] = file_actions |
| 1817 | |
| 1818 | self.pid = os.posix_spawn(executable, args, env, **kwargs) |
| 1819 | self._child_created = True |
| 1820 | |
| 1821 | self._close_pipe_fds(p2cread, p2cwrite, |
| 1822 | c2pread, c2pwrite, |
| 1823 | errread, errwrite) |
| 1824 | |
| 1825 | def _execute_child(self, args, executable, preexec_fn, close_fds, |
| 1826 | pass_fds, cwd, env, |
no test coverage detected