本文整理汇总了Python中resource.error方法的典型用法代码示例。如果您正苦于以下问题:Python resource.error方法的具体用法?Python resource.error怎么用?Python resource.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource.error方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handles_closed_on_exception
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_handles_closed_on_exception(self):
# If CreateProcess exits with an error, ensure the
# duplicate output handles are released
ifhandle, ifname = tempfile.mkstemp()
ofhandle, ofname = tempfile.mkstemp()
efhandle, efname = tempfile.mkstemp()
try:
subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
stderr=efhandle)
except OSError:
os.close(ifhandle)
os.remove(ifname)
os.close(ofhandle)
os.remove(ofname)
os.close(efhandle)
os.remove(efname)
self.assertFalse(os.path.exists(ifname))
self.assertFalse(os.path.exists(ofname))
self.assertFalse(os.path.exists(efname))
示例2: __enter__
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def __enter__(self):
"""Try to save previous ulimit, then set it to (0, 0)."""
if resource is not None:
try:
self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
except (ValueError, resource.error):
pass
if sys.platform == 'darwin':
# Check if the 'Crash Reporter' on OSX was configured
# in 'Developer' mode and warn that it will get triggered
# when it is.
#
# This assumes that this context manager is used in tests
# that might trigger the next manager.
value = subprocess.Popen(['/usr/bin/defaults', 'read',
'com.apple.CrashReporter', 'DialogType'],
stdout=subprocess.PIPE).communicate()[0]
if value.strip() == b'developer':
print "this tests triggers the Crash Reporter, that is intentional"
sys.stdout.flush()
示例3: find_available_port
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def find_available_port(port_range=(49152, 65535), max_tries=1000):
low, high = port_range
port = low
try_no = 0
while try_no < max_tries:
try_no += 1
port = random.randint(low, high)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.bind(('localhost', port))
except socket.error as e:
if e.errno == errno.EADDRINUSE:
continue
raise
finally:
sock.close()
break
else:
port = None
return port
示例4: test_handles_closed_on_exception
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_handles_closed_on_exception(self):
# If CreateProcess exits with an error, ensure the
# duplicate output handles are released
ifhandle, ifname = mkstemp()
ofhandle, ofname = mkstemp()
efhandle, efname = mkstemp()
try:
subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
stderr=efhandle)
except OSError:
os.close(ifhandle)
os.remove(ifname)
os.close(ofhandle)
os.remove(ofname)
os.close(efhandle)
os.remove(efname)
self.assertFalse(os.path.exists(ifname))
self.assertFalse(os.path.exists(ofname))
self.assertFalse(os.path.exists(efname))
示例5: __exit__
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def __exit__(self, *args):
"""Return core file behavior to default."""
if self.old_limit is None:
return
if resource is not None:
try:
resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
except (ValueError, resource.error):
pass
示例6: test_preexec_errpipe_does_not_double_close_pipes
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_preexec_errpipe_does_not_double_close_pipes(self):
"""Issue16140: Don't double close pipes on preexec error."""
def raise_it():
raise RuntimeError("force the _execute_child() errpipe_data path.")
with self.assertRaises(RuntimeError):
self._TestExecuteChildPopen(
self, [sys.executable, "-c", "pass"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, preexec_fn=raise_it)
示例7: test_wait_when_sigchild_ignored
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_wait_when_sigchild_ignored(self):
# NOTE: sigchild_ignore.py may not be an effective test on all OSes.
sigchild_ignore = test_support.findfile("sigchild_ignore.py",
subdir="subprocessdata")
p = subprocess.Popen([sys.executable, sigchild_ignore],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
self.assertEqual(0, p.returncode, "sigchild_ignore.py exited"
" non-zero with this error:\n%s" % stderr)
示例8: bump_rlimit_nofile
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def bump_rlimit_nofile() -> None:
try:
fno_soft, fno_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
except resource.error:
logger.warning('could not read RLIMIT_NOFILE')
else:
if fno_soft < defines.EDGEDB_MIN_RLIMIT_NOFILE:
try:
resource.setrlimit(
resource.RLIMIT_NOFILE,
(min(defines.EDGEDB_MIN_RLIMIT_NOFILE, fno_hard),
fno_hard))
except resource.error:
logger.warning('could not set RLIMIT_NOFILE')
示例9: set_monitor
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def set_monitor():
"""Sets up a following call to daemonize() to fork a supervisory process to
monitor the daemon and restart it if it dies due to an error signal."""
global _monitor
_monitor = True
示例10: _fork_notify_startup
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _fork_notify_startup(fd):
if fd is not None:
error, bytes_written = ovs.socket_util.write_fully(fd, "0")
if error:
sys.stderr.write("could not write to pipe\n")
sys.exit(1)
os.close(fd)
示例11: _suppress_core_files
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _suppress_core_files(self):
"""Try to prevent core files from being created.
Returns previous ulimit if successful, else None.
"""
try:
import resource
old_limit = resource.getrlimit(resource.RLIMIT_CORE)
resource.setrlimit(resource.RLIMIT_CORE, (0,0))
return old_limit
except (ImportError, ValueError, resource.error):
return None
示例12: _unsuppress_core_files
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _unsuppress_core_files(self, old_limit):
"""Return core file behavior to default."""
if old_limit is None:
return
try:
import resource
resource.setrlimit(resource.RLIMIT_CORE, old_limit)
except (ImportError, ValueError, resource.error):
return
示例13: mkdir
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def mkdir(path):
"""Make directory at the specified local path with special error handling.
"""
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
示例14: raise_num_file
# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def raise_num_file(nofile_atleast=4096):
try:
import resource as res
except ImportError: #Windows
res = None
if res is None:
return (None,)*2
# what is current ulimit -n setting?
soft,ohard = res.getrlimit(res.RLIMIT_NOFILE)
hard = ohard
# increase limit (soft and even hard) if needed
if soft < nofile_atleast:
soft = nofile_atleast
if hard<soft:
hard = soft
#logger.warning('setting soft & hard ulimit -n {} {}'.format(soft,hard))
try:
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except (ValueError,res.error):
try:
hard = soft
logger.warning('trouble with max limit, retrying with soft,hard {},{}'.format(soft,hard))
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except Exception:
logger.warning('failed to set ulimit')
soft,hard = res.getrlimit(res.RLIMIT_NOFILE)
return soft,hard