Python errno.EBUSY Examples

The following are 30 code examples of errno.EBUSY(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module errno , or try the search function .
Example #1
Source File: test_os.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def sendfile_wrapper(self, sock, file, offset, nbytes, headers=[], trailers=[]):
        """A higher level wrapper representing how an application is
        supposed to use sendfile().
        """
        while 1:
            try:
                if self.SUPPORT_HEADERS_TRAILERS:
                    return os.sendfile(sock, file, offset, nbytes, headers,
                                       trailers)
                else:
                    return os.sendfile(sock, file, offset, nbytes)
            except OSError as err:
                if err.errno == errno.ECONNRESET:
                    # disconnected
                    raise
                elif err.errno in (errno.EAGAIN, errno.EBUSY):
                    # we have to retry send data
                    continue
                else:
                    raise 
Example #2
Source File: test_os.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def sendfile_wrapper(self, sock, file, offset, nbytes, headers=[], trailers=[]):
        """A higher level wrapper representing how an application is
        supposed to use sendfile().
        """
        while 1:
            try:
                if self.SUPPORT_HEADERS_TRAILERS:
                    return os.sendfile(sock, file, offset, nbytes, headers,
                                       trailers)
                else:
                    return os.sendfile(sock, file, offset, nbytes)
            except OSError as err:
                if err.errno == errno.ECONNRESET:
                    # disconnected
                    raise
                elif err.errno in (errno.EAGAIN, errno.EBUSY):
                    # we have to retry send data
                    continue
                else:
                    raise 
Example #3
Source File: test_paste.py    From modern-paste with MIT License 6 votes vote down vote up
def test_scrub_inactive_pastes_error(self):
        pastes = [util.testing.PasteFactory.generate(expiry_time=None) for _ in range(15)]
        [util.testing.AttachmentFactory.generate(paste_id=paste.paste_id, file_name='file') for paste in pastes]
        [database.paste.deactivate_paste(paste.paste_id) for paste in pastes[:10]]

        with mock.patch.object(shutil, 'rmtree') as mock_rmtree:
            mock_rmtree.side_effect = OSError(errno.EBUSY)

            self.assertRaises(
                OSError,
                database.paste.scrub_inactive_pastes,
            )

        with mock.patch.object(shutil, 'rmtree') as mock_rmtree:
            mock_rmtree.side_effect = OSError(errno.ENOENT)

            for paste in pastes:
                self.assertIsNotNone(database.paste.get_paste_by_id(paste.paste_id)) 
Example #4
Source File: test_assemblers.py    From osbuild with Apache License 2.0 6 votes vote down vote up
def loop_create_device(ctl, fd, offset=None, sizelimit=None):
    while True:
        lo = loop.Loop(ctl.get_unbound())
        try:
            lo.set_fd(fd)
        except OSError as e:
            lo.close()
            if e.errno == errno.EBUSY:
                continue
            raise e
        try:
            lo.set_status(offset=offset, sizelimit=sizelimit, autoclear=True)
        except BlockingIOError:
            lo.clear_fd()
            lo.close()
            continue
        break
    try:
        yield lo
    finally:
        lo.close() 
Example #5
Source File: test_linuxaudiodev.py    From medicare-demo with Apache License 2.0 6 votes vote down vote up
def play_sound_file(path):
    fp = open(path, 'r')
    size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
    data = fp.read()
    fp.close()

    if enc != SND_FORMAT_MULAW_8:
        print "Expect .au file with 8-bit mu-law samples"
        return

    try:
        a = linuxaudiodev.open('w')
    except linuxaudiodev.error, msg:
        if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
            raise TestSkipped, msg
        raise TestFailed, msg

    # convert the data to 16-bit signed 
Example #6
Source File: test_os.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def sendfile_wrapper(self, sock, file, offset, nbytes, headers=[], trailers=[]):
        """A higher level wrapper representing how an application is
        supposed to use sendfile().
        """
        while 1:
            try:
                if self.SUPPORT_HEADERS_TRAILERS:
                    return os.sendfile(sock, file, offset, nbytes, headers,
                                       trailers)
                else:
                    return os.sendfile(sock, file, offset, nbytes)
            except OSError as err:
                if err.errno == errno.ECONNRESET:
                    # disconnected
                    raise
                elif err.errno in (errno.EAGAIN, errno.EBUSY):
                    # we have to retry send data
                    continue
                else:
                    raise 
Example #7
Source File: serial.py    From libpebble2 with MIT License 5 votes vote down vote up
def connect(self):
        try:
            self.connection = serial.Serial(self.device, 115200)
        except OSError as e:
            if e.errno == errno.EBUSY:
                raise ConnectionError("Could not connect to Pebble.")
            else:
                raise 
Example #8
Source File: test_ossaudiodev.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def play_sound_file(data, rate, ssize, nchannels):
    try:
        dsp = ossaudiodev.open('w')
    except IOError, msg:
        if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
            raise TestSkipped, msg
        raise TestFailed, msg

    # at least check that these methods can be invoked 
Example #9
Source File: handlers.py    From pyftpdlib with MIT License 5 votes vote down vote up
def initiate_sendfile(self):
        """A wrapper around sendfile."""
        try:
            sent = sendfile(self._fileno, self._filefd, self._offset,
                            self.ac_out_buffer_size)
        except OSError as err:
            if err.errno in _ERRNOS_RETRY or err.errno == errno.EBUSY:
                return
            elif err.errno in _ERRNOS_DISCONNECTED:
                self.handle_close()
            else:
                if self.tot_bytes_sent == 0:
                    logger.warning(
                        "sendfile() failed; falling back on using plain send")
                    raise _GiveUpOnSendfile
                else:
                    raise
        else:
            if sent == 0:
                # this signals the channel that the transfer is completed
                self.discard_buffers()
                self.handle_close()
            else:
                self._offset += sent
                self.tot_bytes_sent += sent

    # --- utility methods 
Example #10
Source File: test_linuxaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = linuxaudiodev.open('w')
    except linuxaudiodev.error, msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #11
Source File: test_ossaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, IOError), msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #12
Source File: test_ossaudiodev.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def play_sound_file(self, data, rate, ssize, nchannels):
        try:
            dsp = ossaudiodev.open('w')
        except IOError, msg:
            if msg.args[0] in (errno.EACCES, errno.ENOENT,
                               errno.ENODEV, errno.EBUSY):
                raise unittest.SkipTest(msg)
            raise

        # at least check that these methods can be invoked 
Example #13
Source File: test_sendfile.py    From pysendfile with MIT License 5 votes vote down vote up
def test_flags(self):
            try:
                sendfile.sendfile(self.sockno, self.fileno, 0, BUFFER_LEN,
                                  flags=sendfile.SF_NODISKIO)
            except OSError:
                err = sys.exc_info()[1]
                if err.errno not in (errno.EBUSY, errno.EAGAIN):
                    raise
    # --- corner cases 
Example #14
Source File: test_ossaudiodev.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #15
Source File: error.py    From libnl with GNU Lesser General Public License v2.1 5 votes vote down vote up
def nl_syserr2nlerr(error_):
    """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84."""
    error_ = abs(error_)
    legend = {
        errno.EBADF: libnl.errno_.NLE_BAD_SOCK,
        errno.EADDRINUSE: libnl.errno_.NLE_EXIST,
        errno.EEXIST: libnl.errno_.NLE_EXIST,
        errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR,
        errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND,
        errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND,
        errno.EINTR: libnl.errno_.NLE_INTR,
        errno.EAGAIN: libnl.errno_.NLE_AGAIN,
        errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK,
        errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL,
        errno.EFAULT: libnl.errno_.NLE_INVAL,
        errno.EACCES: libnl.errno_.NLE_NOACCESS,
        errno.EINVAL: libnl.errno_.NLE_INVAL,
        errno.ENOBUFS: libnl.errno_.NLE_NOMEM,
        errno.ENOMEM: libnl.errno_.NLE_NOMEM,
        errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT,
        errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH,
        errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP,
        errno.EPERM: libnl.errno_.NLE_PERM,
        errno.EBUSY: libnl.errno_.NLE_BUSY,
        errno.ERANGE: libnl.errno_.NLE_RANGE,
        errno.ENODEV: libnl.errno_.NLE_NODEV,
    }
    return int(legend.get(error_, libnl.errno_.NLE_FAILURE)) 
Example #16
Source File: test_ossaudiodev.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #17
Source File: test_config.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_write_config_errors_if_unexpected_exception(self):
        dnsconfig = DNSConfig()
        exception = IOError(errno.EBUSY, factory.make_string())
        self.patch(config, "atomic_write", Mock(side_effect=exception))
        self.assertRaises(IOError, dnsconfig.write_config) 
Example #18
Source File: test_os.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_flags(self):
        try:
            os.sendfile(self.sockno, self.fileno, 0, 4096,
                        flags=os.SF_NODISKIO)
        except OSError as err:
            if err.errno not in (errno.EBUSY, errno.EAGAIN):
                raise 
Example #19
Source File: remoteloop.py    From osbuild with Apache License 2.0 5 votes vote down vote up
def _create_device(self, fd, dir_fd, offset=None, sizelimit=None):
        while True:
            # Getting an unbound loopback device and attaching a backing
            # file descriptor to it is racy, so we must use a retry loop
            lo = loop.Loop(self.ctl.get_unbound())
            try:
                lo.set_fd(fd)
            except OSError as e:
                lo.close()
                if e.errno == errno.EBUSY:
                    continue
                raise e
            # `set_status` returns EBUSY when the pages from the previously
            # bound file have not been fully cleared yet.
            try:
                lo.set_status(offset=offset, sizelimit=sizelimit, autoclear=True)
            except BlockingIOError:
                lo.clear_fd()
                lo.close()
                continue
            break

        lo.mknod(dir_fd)
        # Pin the Loop objects so they are only released when the LoopServer
        # is destroyed.
        self.devs.append(lo)
        return lo.devname 
Example #20
Source File: test_ossaudiodev.py    From android_universal with MIT License 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, OSError) as msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise
    dsp.close()
    support.run_unittest(__name__) 
Example #21
Source File: os_ext.py    From reframe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def rmtree(*args, max_retries=3, **kwargs):
    '''Persistent version of ``shutil.rmtree()``.

    If ``shutil.rmtree()`` fails with ``ENOTEMPTY`` or ``EBUSY``, retry up to
    ``max_retries`times to delete the directory.

    This version of ``rmtree()`` is mostly provided to work around a race
    condition between when ``sacct`` reports a job as completed and when the
    Slurm epilog runs. See https://github.com/eth-cscs/reframe/issues/291 for
    more information.
    Furthermore, it offers a work around for nfs file systems where a ``.nfs*``
    file may be present during the ``rmtree()`` call which throws a busy
    device/resource error. See https://github.com/eth-cscs/reframe/issues/712
    for more information.

    ``args`` and ``kwargs`` are passed through to ``shutil.rmtree()``.

    If ``onerror``  is specified in  ``kwargs`` and is not  :class:`None`, this
    function is completely equivalent to ``shutil.rmtree()``.
    '''
    if 'onerror' in kwargs and kwargs['onerror'] is not None:
        shutil.rmtree(*args, **kwargs)
        return

    for i in range(max_retries):
        try:
            shutil.rmtree(*args, **kwargs)
            return
        except OSError as e:
            if i == max_retries:
                raise
            elif e.errno in {errno.ENOTEMPTY, errno.EBUSY}:
                pass
            else:
                raise 
Example #22
Source File: test_ossaudiodev.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def play_sound_file(self, data, rate, ssize, nchannels):
        try:
            dsp = ossaudiodev.open('w')
        except IOError, msg:
            if msg.args[0] in (errno.EACCES, errno.ENOENT,
                               errno.ENODEV, errno.EBUSY):
                raise unittest.SkipTest(msg)
            raise

        # at least check that these methods can be invoked 
Example #23
Source File: test_linuxaudiodev.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_main():
    try:
        dsp = linuxaudiodev.open('w')
    except linuxaudiodev.error, msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #24
Source File: test_ossaudiodev.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, IOError), msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #25
Source File: test_ossaudiodev.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def play_sound_file(self, data, rate, ssize, nchannels):
        try:
            dsp = ossaudiodev.open('w')
        except IOError, msg:
            if msg.args[0] in (errno.EACCES, errno.ENOENT,
                               errno.ENODEV, errno.EBUSY):
                raise unittest.SkipTest(msg)
            raise

        # at least check that these methods can be invoked 
Example #26
Source File: test_os.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_flags(self):
        try:
            os.sendfile(self.sockno, self.fileno, 0, 4096,
                        flags=os.SF_NODISKIO)
        except OSError as err:
            if err.errno not in (errno.EBUSY, errno.EAGAIN):
                raise 
Example #27
Source File: test_ossaudiodev.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = ossaudiodev.open('w')
    except (ossaudiodev.error, IOError), msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT,
                           errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #28
Source File: resctrl.py    From workload-collocation-agent with Apache License 2.0 5 votes vote down vote up
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')) 
Example #29
Source File: test_linuxaudiodev.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_main():
    try:
        dsp = linuxaudiodev.open('w')
    except linuxaudiodev.error, msg:
        if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
            raise unittest.SkipTest(msg)
        raise 
Example #30
Source File: setup.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def setup(self, tty):
        print_info("Searching your system for contactless devices")
    
        found = 0
        for vid, pid, bus, dev in nfc.clf.transport.USB.find("usb"):
            if (vid, pid) in nfc.clf.device.usb_device_map:
                path = "usb:{0:03d}:{1:03d}".format(bus, dev)
                try:
                    clf = nfc.ContactlessFrontend(path)
                    print_ok_raw(f"** found {clf.device}")
                    clf.close()
                    found += 1
                except IOError as error:
                    if error.errno == errno.EACCES:
                        self.usb_device_access_denied(bus, dev, vid, pid, path)
                    elif error.errno == errno.EBUSY:
                        self.usb_device_found_is_busy(bus, dev, vid, pid, path)
    
        if tty:
            for dev in nfc.clf.transport.TTY.find("tty")[0]:
                path = f"tty:{dev[8:]}"
                try:
                    clf = nfc.ContactlessFrontend(path)
                    print_ok_raw(f"** found {clf.device}")
                    clf.close()
                    found += 1
                except IOError as error:
                    if error.errno == errno.EACCES:
                        print_error("access denied for device with path %s" % path)
                    elif error.errno == errno.EBUSY:
                        print_error("the device with path %s is busy" % path)
        else:
            print_info("I'm not trying serial devices because you haven't told me")
            print("-- turn the option 'tty' to True to have me looking")
            print("-- but beware that this may break other serial devs")
    
        if not found:
            print_error("Sorry, but I couldn't find any contactless device")