本文整理汇总了Python中os.get_inheritable方法的典型用法代码示例。如果您正苦于以下问题:Python os.get_inheritable方法的具体用法?Python os.get_inheritable怎么用?Python os.get_inheritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.get_inheritable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pass_fds_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_pass_fds_inheritable(self):
script = support.findfile("fd_status.py", subdir="subprocessdata")
inheritable, non_inheritable = os.pipe()
self.addCleanup(os.close, inheritable)
self.addCleanup(os.close, non_inheritable)
os.set_inheritable(inheritable, True)
os.set_inheritable(non_inheritable, False)
pass_fds = (inheritable, non_inheritable)
args = [sys.executable, script]
args += list(map(str, pass_fds))
p = subprocess.Popen(args,
stdout=subprocess.PIPE, close_fds=True,
pass_fds=pass_fds)
output, ignored = p.communicate()
fds = set(map(int, output.split(b',')))
# the inheritable file descriptor must be inherited, so its inheritable
# flag must be set in the child process after fork() and before exec()
self.assertEqual(fds, set(pass_fds), "output=%a" % output)
# inheritable flag must not be changed in the parent process
self.assertEqual(os.get_inheritable(inheritable), True)
self.assertEqual(os.get_inheritable(non_inheritable), False)
示例2: test_dup2
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_dup2(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)
# inheritable by default
fd2 = os.open(__file__, os.O_RDONLY)
try:
os.dup2(fd, fd2)
self.assertEqual(os.get_inheritable(fd2), True)
finally:
os.close(fd2)
# force non-inheritable
fd3 = os.open(__file__, os.O_RDONLY)
try:
os.dup2(fd, fd3, inheritable=False)
self.assertEqual(os.get_inheritable(fd3), False)
finally:
os.close(fd3)
示例3: test_pipe2
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_pipe2(self):
self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
self.assertRaises(TypeError, os.pipe2, 0, 0)
# try calling with flags = 0, like os.pipe()
r, w = os.pipe2(0)
os.close(r)
os.close(w)
# test flags
r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
self.addCleanup(os.close, r)
self.addCleanup(os.close, w)
self.assertFalse(os.get_inheritable(r))
self.assertFalse(os.get_inheritable(w))
self.assertFalse(os.get_blocking(r))
self.assertFalse(os.get_blocking(w))
# try reading from an empty pipe: this should fail, not block
self.assertRaises(OSError, os.read, r, 1)
# try a write big enough to fill-up the pipe: this should either
# fail or perform a partial write, not block
try:
os.write(w, b'x' * support.PIPE_MAX_SIZE)
except OSError:
pass
示例4: set_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def set_inheritable(fd, inheritable):
# On py34+ we can use os.set_inheritable but < py34 we must polyfill
# with fcntl and SetHandleInformation
if hasattr(os, 'get_inheritable'):
if os.get_inheritable(fd) != inheritable:
os.set_inheritable(fd, inheritable)
elif WIN:
h = get_handle(fd)
flags = winapi.HANDLE_FLAG_INHERIT if inheritable else 0
winapi.SetHandleInformation(h, winapi.HANDLE_FLAG_INHERIT, flags)
else:
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
if inheritable:
new_flags = flags & ~fcntl.FD_CLOEXEC
else:
new_flags = flags | fcntl.FD_CLOEXEC
if new_flags != flags:
fcntl.fcntl(fd, fcntl.F_SETFD, new_flags)
示例5: test_pipe2
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_pipe2(self):
self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
self.assertRaises(TypeError, os.pipe2, 0, 0)
# try calling with flags = 0, like os.pipe()
r, w = os.pipe2(0)
os.close(r)
os.close(w)
# test flags
r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
self.addCleanup(os.close, r)
self.addCleanup(os.close, w)
self.assertFalse(os.get_inheritable(r))
self.assertFalse(os.get_inheritable(w))
self.assertTrue(fcntl.fcntl(r, fcntl.F_GETFL) & os.O_NONBLOCK)
self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFL) & os.O_NONBLOCK)
# try reading from an empty pipe: this should fail, not block
self.assertRaises(OSError, os.read, r, 1)
# try a write big enough to fill-up the pipe: this should either
# fail or perform a partial write, not block
try:
os.write(w, b'x' * support.PIPE_MAX_SIZE)
except OSError:
pass
示例6: get_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def get_inheritable(self):
return os.get_handle_inheritable(self.fileno())
示例7: get_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def get_inheritable(self):
return os.get_handle_inheritable(self.fileno())
示例8: test_open_non_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_open_non_inheritable(self):
fileobj = open(__file__)
with fileobj:
self.assertFalse(os.get_inheritable(fileobj.fileno()))
示例9: test_fd_non_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_fd_non_inheritable(self):
kqueue = select.kqueue()
self.addCleanup(kqueue.close)
self.assertEqual(os.get_inheritable(kqueue.fileno()), False)
示例10: test_noinherit
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_noinherit(self):
# _mkstemp_inner file handles are not inherited by child processes
if support.verbose:
v="v"
else:
v="q"
file = self.do_create()
self.assertEqual(os.get_inheritable(file.fd), False)
fd = "%d" % file.fd
try:
me = __file__
except NameError:
me = sys.argv[0]
# We have to exec something, so that FD_CLOEXEC will take
# effect. The core of this test is therefore in
# tf_inherit_check.py, which see.
tester = os.path.join(os.path.dirname(os.path.abspath(me)),
"tf_inherit_check.py")
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
# but an arg with embedded spaces should be decorated with double
# quotes on each end
if sys.platform == 'win32':
decorated = '"%s"' % sys.executable
tester = '"%s"' % tester
else:
decorated = sys.executable
retval = os.spawnl(os.P_WAIT, sys.executable, decorated, tester, v, fd)
self.assertFalse(retval < 0,
"child process caught fatal signal %d" % -retval)
self.assertFalse(retval > 0, "child process reports failure %d"%retval)
示例11: test_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_inheritable(self):
self.check(os.get_inheritable)
self.check(os.set_inheritable, True)
示例12: test_get_set_inheritable
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_get_set_inheritable(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)
self.assertEqual(os.get_inheritable(fd), False)
os.set_inheritable(fd, True)
self.assertEqual(os.get_inheritable(fd), True)
示例13: test_get_inheritable_cloexec
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_get_inheritable_cloexec(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)
self.assertEqual(os.get_inheritable(fd), False)
# clear FD_CLOEXEC flag
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags &= ~fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
self.assertEqual(os.get_inheritable(fd), True)
示例14: test_open
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_open(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)
self.assertEqual(os.get_inheritable(fd), False)
示例15: test_dup
# 需要导入模块: import os [as 别名]
# 或者: from os import get_inheritable [as 别名]
def test_dup(self):
fd1 = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd1)
fd2 = os.dup(fd1)
self.addCleanup(os.close, fd2)
self.assertEqual(os.get_inheritable(fd2), False)