當前位置: 首頁>>代碼示例>>Python>>正文


Python errno.ENOSPC屬性代碼示例

本文整理匯總了Python中errno.ENOSPC屬性的典型用法代碼示例。如果您正苦於以下問題:Python errno.ENOSPC屬性的具體用法?Python errno.ENOSPC怎麽用?Python errno.ENOSPC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在errno的用法示例。


在下文中一共展示了errno.ENOSPC屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_downloadPageLogsFileCloseError

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def test_downloadPageLogsFileCloseError(self):
        """
        If there is an exception closing the file being written to after the
        connection is prematurely closed, that exception is logged.
        """
        class BrokenFile:
            def write(self, bytes):
                pass

            def close(self):
                raise IOError(ENOSPC, "No file left on device")

        d = client.downloadPage(self.getURL("broken"), BrokenFile())
        d = self.assertFailure(d, client.PartialDownloadError)
        def cbFailed(ignored):
            self.assertEqual(len(self.flushLoggedErrors(IOError)), 1)
        d.addCallback(cbFailed)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_webclient.py

示例2: test_out_of_disk_space_message

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def test_out_of_disk_space_message(self):
        # this test can only be run as root becasue it needs to create
        # a tmpfs temporary partition to invoke the correct exception
        def executeTest(ramdiskdir):
            openFiles = Storage.OpenFiles(10)
            os.system('mount -t tmpfs -o size=1M tmpfs %s' % ramdiskdir)
            try:
                paths = [os.path.join(ramdiskdir, 'test-%s' % ix) for ix in range(10)]
                toWrite = [chr((ix + c) % 255) for c in range(1024) for ix in range(32)] * 32
                for string in toWrite:
                    path = random.choice(paths)
                    openFiles.append(path, string)
            except OSError as e:
                self.assertEqual(e.errno, errno.ENOSPC)
                openFiles.shutdown()
                raise
        if os.geteuid() == 0:
            ramdiskdir = tempfile.mkdtemp()
            self.assertRaises(OSError, lambda : executeTest(ramdiskdir))
            self.assertTrue(os.system('umount %s' %  ramdiskdir) == 0)
        else:
            logging.warn("this test must be run as a superuser!") 
開發者ID:ufora,項目名稱:ufora,代碼行數:24,代碼來源:FileIO_test.py

示例3: _check_space

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def _check_space(self, size):
        try:
            vfs_stat = os.statvfs(self._cache_folder)
            free_space = vfs_stat.f_bsize * vfs_stat.f_bavail

            cache_entries = []
            for name in os.listdir(self._cache_folder):
                cache_entries.append((name, os.lstat(os.path.join(self._cache_folder, name))))
        except Exception as e:
            if not isinstance(e, OSError):
                log.exception("Error while checking space")
                return

        cache_size = sum(st.st_size for (_, st) in cache_entries)

        # % of free space that cache is allowed to take up
        N = 0.10

        if (cache_size + size) / (cache_size + free_space) > N:
            raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC)) 
開發者ID:rianhunter,項目名稱:dbxfs,代碼行數:22,代碼來源:cachingfs.py

示例4: test_downloadPageLogsFileCloseError

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def test_downloadPageLogsFileCloseError(self):
        """
        If there is an exception closing the file being written to after the
        connection is prematurely closed, that exception is logged.
        """
        class BrokenFile:
            def write(self, bytes):
                pass

            def close(self):
                raise IOError(ENOSPC, "No file left on device")

        d = client.downloadPage(self.getURL("broken"), BrokenFile())
        d = self.assertFailure(d, client.PartialDownloadError)
        def cbFailed(ignored):
            self.assertEquals(len(self.flushLoggedErrors(IOError)), 1)
        d.addCallback(cbFailed)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:20,代碼來源:test_webclient.py

示例5: test_input_conversion

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def test_input_conversion(self):
        obj = QIIME2Type(IntSequence1.to_ast(), repr(IntSequence1))

        with self.assertRaisesRegex(click.exceptions.BadParameter,
                                    f'{self.tempdir!r} is not a QIIME 2 '
                                    'Artifact'):
            obj._convert_input(self.tempdir, None, None)

        with self.assertRaisesRegex(click.exceptions.BadParameter,
                                    "'x' is not a valid filepath"):
            obj._convert_input('x', None, None)

        # This is to ensure the temp in the regex matches the temp used in the
        # method under test in type.py
        temp = tempfile.tempdir
        with unittest.mock.patch('qiime2.sdk.Result.load',
                                 side_effect=OSError(errno.ENOSPC,
                                                     'No space left on '
                                                     'device')):
            with self.assertRaisesRegex(click.exceptions.BadParameter,
                                        f'{temp!r}.*'
                                        f'{self.artifact1_path!r}.*'
                                        f'{temp!r}'):
                obj._convert_input(self.artifact1_path, None, None) 
開發者ID:qiime2,項目名稱:q2cli,代碼行數:26,代碼來源:test_cli.py

示例6: _add_watch_for_path

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def _add_watch_for_path(self, path):
    logging.debug('_add_watch_for_path(%r)', path)

    for dirpath, directories, _ in itertools.chain(
        [('', [path], None)],
        os.walk(path, topdown=True, followlinks=True)):
      for directory in directories:
        directory_path = os.path.join(dirpath, directory)
        # dirpath cannot be used as the parent directory path because it is the
        # empty string for symlinks :-(
        parent_path = os.path.dirname(directory_path)

        watch_descriptor = InotifyFileWatcher._libc.inotify_add_watch(
            self._inotify_fd,
            ctypes.create_string_buffer(directory_path),
            _INTERESTING_INOTIFY_EVENTS)
        if watch_descriptor < 0:
          if ctypes.get_errno() == errno.ENOSPC:
            logging.warning(
                'There are too many directories in your application for '
                'changes in all of them to be monitored. You may have to '
                'restart the development server to see some changes to your '
                'files.')
            return
          error = OSError('could not add watch for %r' % directory_path)
          error.errno = ctypes.get_errno()
          error.strerror = errno.errorcode[ctypes.get_errno()]
          error.filename = directory_path
          raise error

        if parent_path in self._directory_to_subdirs:
          self._directory_to_subdirs[parent_path].add(directory_path)
        self._watch_to_directory[watch_descriptor] = directory_path
        self._directory_to_watch_descriptor[directory_path] = watch_descriptor
        self._directory_to_subdirs[directory_path] = set() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:37,代碼來源:inotify_file_watcher.py

示例7: _create_controlgroup_directory

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def _create_controlgroup_directory(self):
        """Create control group directory"""
        try:
            log.log(logger.TRACE, 'resctrl: makedirs(%s)', self.fullpath)
            os.makedirs(self.fullpath, exist_ok=True)
        except OSError as e:
            if e.errno == errno.ENOSPC:  # "No space left on device"
                raise OutOfClosidsException(
                    "Limit of workloads reached! (Oot of available CLoSes/RMIDs!)")
            raise 
開發者ID:intel,項目名稱:workload-collocation-agent,代碼行數:12,代碼來源:resctrl.py

示例8: add_pids

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def add_pids(self, pids, mongroup_name):
        """Adds the pids to the resctrl group and creates mongroup with the pids.
           If the resctrl group does not exists creates it (lazy creation).
           If the mongroup exists adds pids to the group (no error will be thrown)."""
        assert mongroup_name is not None and len(mongroup_name) > 0, 'mongroup_name cannot be empty'

        if self.name != RESCTRL_ROOT_NAME:
            log.debug('creating resctrl group %r', self.name)
            self._create_controlgroup_directory()

        # CTRL GROUP
        # add pids to /tasks file
        log.debug('add_pids: %d pids to %r', len(pids), os.path.join(self.fullpath, 'tasks'))
        self._add_pids_to_tasks_file(pids, os.path.join(self.fullpath, 'tasks'))

        # MON GROUP
        # create mongroup ...
        mongroup_fullpath = self._get_mongroup_fullpath(mongroup_name)
        try:
            log.log(logger.TRACE, 'resctrl: makedirs(%s)', mongroup_fullpath)
            os.makedirs(mongroup_fullpath, exist_ok=True)
        except OSError as e:
            if e.errno == errno.ENOSPC:  # "No space left on device"
                raise Exception("Limit of workloads reached! (Out of available CLoSes/RMIDs!)")
            if e.errno == errno.EBUSY:  # "Device or resource busy"
                raise Exception("Out of RMIDs! Too many RMIDs used or in "
                                "limbo. If you encountered this problem it "
                                "is probably related to one of known issues "
                                "mentioned in Skylake processor's errata."
                                "You could try to increase max "
                                "threshold occupancy in /sys/fs/resctrl"
                                "/info/L3_MON/max_threshold_occupancy file.")
            raise
        # ... and write the pids to the mongroup
        log.debug('add_pids: %d pids to %r', len(pids), os.path.join(mongroup_fullpath, 'tasks'))
        self._add_pids_to_tasks_file(pids, os.path.join(mongroup_fullpath, 'tasks')) 
開發者ID:intel,項目名稱:workload-collocation-agent,代碼行數:38,代碼來源:resctrl.py

示例9: resize_file

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def resize_file(fobj, diff, BUFFER_SIZE=2 ** 16):
    """Resize a file by `diff`.

    New space will be filled with zeros.

    Args:
        fobj (fileobj)
        diff (int): amount of size to change
    Raises:
        IOError
    """

    fobj.seek(0, 2)
    filesize = fobj.tell()

    if diff < 0:
        if filesize + diff < 0:
            raise ValueError
        # truncate flushes internally
        fobj.truncate(filesize + diff)
    elif diff > 0:
        try:
            while diff:
                addsize = min(BUFFER_SIZE, diff)
                fobj.write(b"\x00" * addsize)
                diff -= addsize
            fobj.flush()
        except IOError as e:
            if e.errno == errno.ENOSPC:
                # To reduce the chance of corrupt files in case of missing
                # space try to revert the file expansion back. Of course
                # in reality every in-file-write can also fail due to COW etc.
                # Note: IOError gets also raised in flush() due to buffering
                fobj.truncate(filesize)
            raise 
開發者ID:bugatsinho,項目名稱:bugatsinho.github.io,代碼行數:37,代碼來源:_util.py

示例10: oswrite

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def oswrite(self, fh, data):
        if self._writestate:
            return os.write(fh, data)
        else:
            raise OSError(errno.ENOSPC, "Faked Space problem") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_mail.py

示例11: _raise_error

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [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)) 
開發者ID:restran,項目名稱:hacker-scripts,代碼行數:13,代碼來源:inotify_c.py

示例12: lzc_receive_translate_error

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def lzc_receive_translate_error(ret, snapname, fd, force, origin, props):
    if ret == 0:
        return
    if ret == errno.EINVAL:
        if not _is_valid_snap_name(snapname) and not _is_valid_fs_name(snapname):
            raise lzc_exc.NameInvalid(snapname)
        elif len(snapname) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(snapname)
        elif origin is not None and not _is_valid_snap_name(origin):
            raise lzc_exc.NameInvalid(origin)
        else:
            raise lzc_exc.BadStream()
    if ret == errno.ENOENT:
        if not _is_valid_snap_name(snapname):
            raise lzc_exc.NameInvalid(snapname)
        else:
            raise lzc_exc.DatasetNotFound(snapname)
    if ret == errno.EEXIST:
        raise lzc_exc.DatasetExists(snapname)
    if ret == errno.ENOTSUP:
        raise lzc_exc.StreamFeatureNotSupported()
    if ret == errno.ENODEV:
        raise lzc_exc.StreamMismatch(_fs_name(snapname))
    if ret == errno.ETXTBSY:
        raise lzc_exc.DestinationModified(_fs_name(snapname))
    if ret == errno.EBUSY:
        raise lzc_exc.DatasetBusy(_fs_name(snapname))
    if ret == errno.ENOSPC:
        raise lzc_exc.NoSpace(_fs_name(snapname))
    if ret == errno.EDQUOT:
        raise lzc_exc.QuotaExceeded(_fs_name(snapname))
    if ret == errno.ENAMETOOLONG:
        raise lzc_exc.NameTooLong(snapname)
    if ret == errno.EROFS:
        raise lzc_exc.ReadOnlyPool(_pool_name(snapname))
    if ret == errno.EAGAIN:
        raise lzc_exc.SuspendedPool(_pool_name(snapname))

    raise lzc_exc.StreamIOError(ret) 
開發者ID:ClusterHQ,項目名稱:pyzfs,代碼行數:41,代碼來源:_error_translation.py

示例13: __init__

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def __init__(self, code=None, msg='Unknown error'):
        super(XAttrMetadataError, self).__init__(msg)
        self.code = code
        self.msg = msg

        # Parsing code and msg
        if (self.code in (errno.ENOSPC, errno.EDQUOT)
                or 'No space left' in self.msg or 'Disk quota excedded' in self.msg):
            self.reason = 'NO_SPACE'
        elif self.code == errno.E2BIG or 'Argument list too long' in self.msg:
            self.reason = 'VALUE_TOO_LONG'
        else:
            self.reason = 'NOT_SUPPORTED' 
開發者ID:tvalacarta,項目名稱:tvalacarta,代碼行數:15,代碼來源:utils.py

示例14: __init__

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def __init__(self, code=None, msg='Unknown error'):
        super(XAttrMetadataError, self).__init__(msg)
        self.code = code
        self.msg = msg

        # Parsing code and msg
        if (self.code in (errno.ENOSPC, errno.EDQUOT) or
                'No space left' in self.msg or 'Disk quota excedded' in self.msg):
            self.reason = 'NO_SPACE'
        elif self.code == errno.E2BIG or 'Argument list too long' in self.msg:
            self.reason = 'VALUE_TOO_LONG'
        else:
            self.reason = 'NOT_SUPPORTED' 
開發者ID:yasoob,項目名稱:youtube-dl-GUI,代碼行數:15,代碼來源:utils.py

示例15: test_cinder_add_volume_full

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOSPC [as 別名]
def test_cinder_add_volume_full(self):
        e = IOError()
        volume_file = six.BytesIO()
        e.errno = errno.ENOSPC
        fake_volume = mock.MagicMock(id=str(uuid.uuid4()),
                                     status='available',
                                     size=1)
        with mock.patch.object(volume_file, 'write', side_effect=e):
            self.assertRaises(exceptions.StorageFull,
                              self._test_cinder_add, fake_volume, volume_file)
        fake_volume.delete.assert_called_once_with() 
開發者ID:openstack,項目名稱:glance_store,代碼行數:13,代碼來源:test_cinder_store.py


注:本文中的errno.ENOSPC屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。