本文整理汇总了Python中errno.EMFILE属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EMFILE属性的具体用法?Python errno.EMFILE怎么用?Python errno.EMFILE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EMFILE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_urandom_failure
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_urandom_failure(self):
# Check urandom() failing when it is not able to open /dev/random.
# We spawn a new process to make the test more robust (if getrlimit()
# failed to restore the file descriptor limit after this, the whole
# test suite would crash; this actually happened on the OS X Tiger
# buildbot).
code = """if 1:
import errno
import os
import resource
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
try:
os.urandom(16)
except OSError as e:
assert e.errno == errno.EMFILE, e.errno
else:
raise AssertionError("OSError not raised")
"""
assert_python_ok('-c', code)
示例2: exhaust
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def exhaust(self):
"""
Open file descriptors until C{EMFILE} is reached.
"""
# Force a collection to close dangling files.
gc.collect()
try:
while True:
try:
fd = self._fileDescriptorFactory()
except (IOError, OSError) as e:
if e.errno == errno.EMFILE:
break
raise
else:
self._fileDescriptors.append(fd)
except Exception:
self.release()
raise
else:
self._log.info(
"EMFILE reached by opening"
" {openedFileDescriptors} file descriptors.",
openedFileDescriptors=self.count(),
)
示例3: test_releaseRaisesOSError
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_releaseRaisesOSError(self):
"""
An L{OSError} raised within
L{_ExhaustsFileDescriptors.release} with an C{errno} other than
C{EBADF} is reraised to the caller.
"""
fakeFileDescriptors = []
def opensThree():
if len(fakeFileDescriptors) == 3:
raise OSError(errno.EMFILE, "Too many files")
fakeFileDescriptors.append(-1)
return fakeFileDescriptors[-1]
def failingClose(fd):
raise OSError(11, "test_releaseRaisesOSError fake OSError")
exhauster = _ExhaustsFileDescriptors(opensThree,
close=failingClose)
self.assertEqual(exhauster.count(), 0)
exhauster.exhaust()
self.assertGreater(exhauster.count(), 0)
self.assertRaises(OSError, exhauster.release)
示例4: test_reserveEMFILELogged
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_reserveEMFILELogged(self):
"""
If reserving the file descriptor fails because of C{EMFILE},
the exception is suppressed but logged and the reservation
remains unavailable.
"""
exhauster = _ExhaustsFileDescriptors()
self.addCleanup(exhauster.release)
exhauster.exhaust()
self.assertFalse(self.reservedFD.available())
self.reservedFD.reserve()
self.assertFalse(self.reservedFD.available())
errors = self.flushLoggedErrors(OSError, IOError)
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0].value.errno, errno.EMFILE)
示例5: test_runOutOfFiles
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_runOutOfFiles(self):
"""
If the process is out of files, L{Resolver._connectedProtocol}
will give up.
"""
ports = []
class FakeReactor(object):
def listenUDP(self, port, *args, **kwargs):
ports.append(port)
err = OSError(errno.EMFILE, "Out of files :(")
raise CannotListenError(None, port, err)
resolver = client.Resolver(servers=[('example.com', 53)])
resolver._reactor = FakeReactor()
exc = self.assertRaises(CannotListenError, resolver._connectedProtocol)
# The EMFILE-containing exception was raised, and it did not try
# multiple times.
self.assertEqual(exc.socketError.errno, errno.EMFILE)
self.assertEqual(len(ports), 1)
示例6: test_write_device_other_ioerror
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_write_device_other_ioerror(self, mock_io_open):
"""Write device raises an io error for other disk issues."""
mock_io_open.side_effect = IOError(errno.EMFILE, 'Boom')
inputs.NIX = True
led = inputs.LED(None, PATH, NAME)
led._character_device_path = CHARPATH
with self.assertRaises(IOError):
led._write_device # pylint: disable=pointless-statement
示例7: test_no_leaking
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_no_leaking(self):
# Make sure we leak no resources
if not mswindows:
max_handles = 1026 # too much for most UNIX systems
else:
max_handles = 2050 # too much for (at least some) Windows setups
handles = []
try:
for i in range(max_handles):
try:
handles.append(os.open(test_support.TESTFN,
os.O_WRONLY | os.O_CREAT))
except OSError as e:
if e.errno != errno.EMFILE:
raise
break
else:
self.skipTest("failed to reach the file descriptor limit "
"(tried %d)" % max_handles)
# Close a couple of them (should be enough for a subprocess)
for i in range(10):
os.close(handles.pop())
# Loop creating some subprocesses. If one of them leaks some fds,
# the next loop iteration will fail by reaching the max fd limit.
for i in range(15):
p = subprocess.Popen([sys.executable, "-c",
"import sys;"
"sys.stdout.write(sys.stdin.read())"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
data = p.communicate(b"lime")[0]
self.assertEqual(data, b"lime")
finally:
for h in handles:
os.close(h)
test_support.unlink(test_support.TESTFN)
示例8: _raise_error
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def _raise_error():
"""
Raises errors for inotify failures.
"""
err = ctypes.get_errno()
if err == errno.ENOSPC:
raise OSError("inotify watch limit reached")
elif err == errno.EMFILE:
raise OSError("inotify instance limit reached")
else:
raise OSError(os.strerror(err))
示例9: _accept_connection
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def _accept_connection(self, protocol_factory, sock,
sslcontext=None, server=None):
try:
conn, addr = sock.accept()
if self._debug:
logger.debug("%r got a new connection from %r: %r",
server, addr, conn)
conn.setblocking(False)
except (BlockingIOError, InterruptedError, ConnectionAbortedError):
pass # False alarm.
except OSError as exc:
# There's nowhere to send the error, so just log it.
if exc.errno in (errno.EMFILE, errno.ENFILE,
errno.ENOBUFS, errno.ENOMEM):
# Some platforms (e.g. Linux keep reporting the FD as
# ready, so we remove the read handler temporarily.
# We'll try again in a while.
self.call_exception_handler({
'message': 'socket.accept() out of system resource',
'exception': exc,
'socket': sock,
})
self.remove_reader(sock.fileno())
self.call_later(constants.ACCEPT_RETRY_DELAY,
self._start_serving,
protocol_factory, sock, sslcontext, server)
else:
raise # The event loop will catch, log and ignore it.
else:
extra = {'peername': addr}
accept = self._accept_connection2(protocol_factory, conn, extra,
sslcontext, server)
self.create_task(accept)
示例10: test_accept_connection_exception
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_accept_connection_exception(self, m_log):
sock = mock.Mock()
sock.fileno.return_value = 10
sock.accept.side_effect = OSError(errno.EMFILE, 'Too many open files')
self.loop.remove_reader = mock.Mock()
self.loop.call_later = mock.Mock()
self.loop._accept_connection(MyProto, sock)
self.assertTrue(m_log.error.called)
self.assertFalse(sock.close.called)
self.loop.remove_reader.assert_called_with(10)
self.loop.call_later.assert_called_with(constants.ACCEPT_RETRY_DELAY,
# self.loop._start_serving
mock.ANY,
MyProto, sock, None, None)
示例11: test_no_leaking
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_no_leaking(self):
# Make sure we leak no resources
if not mswindows:
max_handles = 1026 # too much for most UNIX systems
else:
max_handles = 2050 # too much for (at least some) Windows setups
handles = []
tmpdir = tempfile.mkdtemp()
try:
for i in range(max_handles):
try:
tmpfile = os.path.join(tmpdir, support.TESTFN)
handles.append(os.open(tmpfile, os.O_WRONLY|os.O_CREAT))
except OSError as e:
if e.errno != errno.EMFILE:
raise
break
else:
self.skipTest("failed to reach the file descriptor limit "
"(tried %d)" % max_handles)
# Close a couple of them (should be enough for a subprocess)
for i in range(10):
os.close(handles.pop())
# Loop creating some subprocesses. If one of them leaks some fds,
# the next loop iteration will fail by reaching the max fd limit.
for i in range(15):
p = subprocess.Popen([sys.executable, "-c",
"import sys;"
"sys.stdout.write(sys.stdin.read())"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
data = p.communicate(b"lime")[0]
self.assertEqual(data, b"lime")
finally:
for h in handles:
os.close(h)
shutil.rmtree(tmpdir)
示例12: test_fd_leak
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_fd_leak(self):
# Since we're opening a lot of FDs, we must be careful to avoid leaks:
# we both check that calling fwalk() a large number of times doesn't
# yield EMFILE, and that the minimum allocated FD hasn't changed.
minfd = os.dup(1)
os.close(minfd)
for i in range(256):
for x in os.fwalk(support.TESTFN):
pass
newfd = os.dup(1)
self.addCleanup(os.close, newfd)
self.assertEqual(newfd, minfd)
示例13: reserve
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def reserve():
"""
Attempt to open the reserved file descriptor; if this fails
because of C{EMFILE}, internal state is reset so that another
reservation attempt can be made.
@raises: Any exception except an L{OSError} or L{IOError}
whose errno is L{EMFILE}.
"""
示例14: __exit__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def __exit__(self, excValue, excType, traceback):
"""
See L{_IFileDescriptorReservation.__exit__}.
"""
try:
self.reserve()
except Exception:
self._log.failure(
"Could not re-reserve EMFILE recovery file descriptor.")
示例15: test_exhaustRaisesOSError
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EMFILE [as 别名]
def test_exhaustRaisesOSError(self):
"""
An L{OSError} raised within
L{_ExhaustsFileDescriptors.exhaust} with an C{errno} other
than C{EMFILE} is reraised to the caller.
"""
def raiseOSError():
raise OSError(errno.EMFILE + 1, "Not EMFILE")
exhauster = _ExhaustsFileDescriptors(raiseOSError)
self.assertRaises(OSError, exhauster.exhaust)