本文整理汇总了Python中errno.EBUSY属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EBUSY属性的具体用法?Python errno.EBUSY怎么用?Python errno.EBUSY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EBUSY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendfile_wrapper
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例2: test_scrub_inactive_pastes_error
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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))
示例3: loop_create_device
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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()
示例4: play_sound_file
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例5: add_pids
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [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'))
示例6: load
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def load(volpath):
"""
Load and return dictionary from the sidecar
"""
vol_type = get_vol_type(volpath)
if not vol_type:
logging.warning("KV delete - could not determine type of volume %s", volpath)
return None
if vol_type == c_uint32(KV_VOL_VIRTUAL).value:
meta_file = lib.DiskLib_SidecarMakeFileName(volpath.encode(),
DVOL_KEY.encode())
else:
meta_file = get_kv_filename(volpath)
if not meta_file:
return None
retry_count = 0
vol_name = vmdk_utils.get_volname_from_vmdk_path(volpath)
while True:
try:
with open(meta_file, "r") as fh:
kv_str = fh.read()
break
except IOError as open_error:
# This is a workaround to the timing/locking with metadata files issue #626
if open_error.errno == errno.EBUSY and retry_count <= vmdk_utils.VMDK_RETRY_COUNT:
logging.warning("Meta file %s busy for load(), retrying...", meta_file)
vmdk_utils.log_volume_lsof(vol_name)
retry_count += 1
time.sleep(vmdk_utils.VMDK_RETRY_SLEEP)
else:
logging.exception("Failed to access %s", meta_file)
return None
try:
return json.loads(kv_str)
except ValueError:
logging.exception("load:Failed to decode meta-data for %s", volpath)
return None
示例7: play_sound_file
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例8: test_main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例9: test_main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例10: test_init_fail_open
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def test_init_fail_open(self, usb_context):
device = self.Device(0x1000, 0x2000, 1, 2, [
self.Settings([
self.Endpoint(0x0004, 0x0002),
self.Endpoint(0x0084, 0x0002),
])
])
device.open = MagicMock()
device.open.side_effect = [
nfc.clf.transport.libusb.USBErrorAccess,
nfc.clf.transport.libusb.USBErrorBusy,
nfc.clf.transport.libusb.USBErrorNoDevice,
]
usb_context.return_value.getDeviceList.return_value = [device]
with pytest.raises(IOError) as excinfo:
nfc.clf.transport.USB(1, 2)
assert excinfo.value.errno == errno.EACCES
with pytest.raises(IOError) as excinfo:
nfc.clf.transport.USB(1, 2)
assert excinfo.value.errno == errno.EBUSY
with pytest.raises(IOError) as excinfo:
nfc.clf.transport.USB(1, 2)
assert excinfo.value.errno == errno.ENODEV
示例11: test_bad_acquire
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def test_bad_acquire(self):
lock_file = os.path.join(self.lock_dir, 'lock')
lock = BrokenLock(lock_file, errno.EBUSY)
self.assertRaises(threading.ThreadError, lock.acquire)
示例12: initiate_sendfile
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
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
示例13: connect_miniterm
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def connect_miniterm(port):
try:
ser = Serial(port, BAUDRATE, parity=PARITY, rtscts=False, xonxoff=False)
return Miniterm(ser, echo=False)
except SerialException as e:
if e.errno == errno.ENOENT:
sys.stderr.write(
"Device %r not found. Check your "
"MicroPython device path settings.\n" % port)
elif e.errno == errno.EBUSY:
# Device is busy. Explain what to do.
sys.stderr.write(
"Found the device, but it is busy. "
"Wait up to 20 seconds, or "
"press the reset button on the "
"back of the device next to the yellow light; "
"then try again.\n"
)
elif e.errno == errno.EACCES:
sys.stderr.write("Found the device, but could not connect.\n".format(port))
sys.stderr.write('%s\n' % (str(e),))
sys.stderr.write('On linux, try adding yourself to the "dialout" group:\n')
sys.stderr.write('sudo usermod -a -G dialout <your-username>\n')
else:
# Try to be as helpful as possible.
sys.stderr.write("Found the device, but could not connect via" +
" port %r: %s\n" % (port, e))
sys.stderr.write("I'm not sure what to suggest. :-(\n")
input("Press ENTER to continue")
sys.exit(1)
示例14: dup2
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def dup2(a, b, timeout=3):
"""Like os.dup2, but retry on EBUSY"""
dup_err = None
# give FDs 3 seconds to not be busy anymore
for i in range(int(10 * timeout)):
try:
return os.dup2(a, b)
except OSError as e:
dup_err = e
if e.errno == errno.EBUSY:
time.sleep(0.1)
else:
raise
if dup_err:
raise dup_err
示例15: lzc_destroy_snaps_translate_errors
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EBUSY [as 别名]
def lzc_destroy_snaps_translate_errors(ret, errlist, snaps, defer):
if ret == 0:
return
def _map(ret, name):
if ret == errno.EEXIST:
return lzc_exc.SnapshotIsCloned(name)
if ret == errno.ENOENT:
return lzc_exc.PoolNotFound(name)
if ret == errno.EBUSY:
return lzc_exc.SnapshotIsHeld(name)
return _generic_exception(ret, name, "Failed to destroy snapshot")
_handle_err_list(ret, errlist, snaps, lzc_exc.SnapshotDestructionFailure, _map)