Python errno.ENOSYS Examples
The following are 30
code examples of errno.ENOSYS().
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: _pslinux.py From teleport with Apache License 2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #2
Source File: _pslinux.py From vnpy_crypto with MIT License | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #3
Source File: _pslinux.py From backdoorme with MIT License | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #4
Source File: _pslinux.py From psutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #5
Source File: _pslinux.py From jarvis with GNU General Public License v2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #6
Source File: _pslinux.py From backdoorme with MIT License | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #7
Source File: construct_setups.py From f5-openstack-agent with Apache License 2.0 | 6 votes |
def _build_stdeb_cfg(wkg): setup_cfg = glob.glob(wkg + "/*-dist/deb_dist/stdeb.cfg") setup = wkg + "/setup_requirements.txt" fmt = "%s (%s)," if not setup_cfg: dist = glob.glob(wkg + "/*-dist") if not dist: print(str(EnvironmentError("Unable to find a *-dist directory"))) print("No dist directory under: " + wkg) exit_cleanly(error_number=errno.ENOSYS) deb_dist = dist[0] + "/deb_dist" try: os.mkdir(deb_dist) except IOError as Error: if not os.path.isdir(deb_dist): print(str(Error)) print("Unable to determine the existence of: " + deb_dist) exit_cleanly(error_number=errno.ENOSYS) setup_cfg = deb_dist + "/stdeb.cfg" else: setup_cfg = setup_cfg[0] _construct_file(setup_cfg, setup, fmt, 'Depends:\n ')
Example #8
Source File: construct_setups.py From f5-openstack-agent with Apache License 2.0 | 6 votes |
def construct_cfgs(**kargs): """construct_cfgs Performs actions to construct either the setup.cfg (rpm) or stdeb.cfg (deb) files as per the operating system specified. This construction is done as per the setup_requirements.txt file from within the working directory specified. This is a very tempermental function by design. It intentionally exits with a non-zero if/when an error has occurred on its own. Therefore, it is not suggested to use this function if you intend to get control back again. """ docker_dir = _check_args(**kargs) if not docker_dir or not os.path.isdir(docker_dir): print("Unable to determine the %s/%s combo under supported versioning" % (kargs['operating_system'], kargs['version'])) exit_cleanly(error_number=errno.ENOSYS) if kargs['operating_system'] == 'redhat': _build_setup_cfg(kargs['working_directory']) elif kargs['operating_system'] == 'ubuntu': _build_stdeb_cfg(kargs['working_directory']) else: print("Unsure of what to do... operating_system(%s) is not recognized!" % kargs['operating_system'])
Example #9
Source File: test_osfs.py From pyfilesystem2 with MIT License | 6 votes |
def test_copy_sendfile(self): # try copying using sendfile with mock.patch.object(osfs, "sendfile") as sendfile: sendfile.side_effect = OSError(errno.ENOSYS, "sendfile not supported") self.test_copy() # check other errors are transmitted self.fs.touch("foo") with mock.patch.object(osfs, "sendfile") as sendfile: sendfile.side_effect = OSError(errno.EWOULDBLOCK) with self.assertRaises(OSError): self.fs.copy("foo", "foo_copy") # check parent exist and is dir with self.assertRaises(errors.ResourceNotFound): self.fs.copy("foo", "spam/eggs") with self.assertRaises(errors.DirectoryExpected): self.fs.copy("foo", "foo_copy/foo")
Example #10
Source File: test_lockfile.py From python-for-android with Apache License 2.0 | 6 votes |
def test_rmlinkError(self): """ An exception raised by L{rmlink} other than C{ENOENT} is passed up to the caller of L{FilesystemLock.lock}. """ def fakeRmlink(name): raise OSError(errno.ENOSYS, None) self.patch(lockfile, 'rmlink', fakeRmlink) def fakeKill(pid, signal): if signal != 0: raise OSError(errno.EPERM, None) if pid == 43125: raise OSError(errno.ESRCH, None) self.patch(lockfile, 'kill', fakeKill) lockf = self.mktemp() # Make it appear locked so it has to use readlink lockfile.symlink(str(43125), lockf) lock = lockfile.FilesystemLock(lockf) exc = self.assertRaises(OSError, lock.lock) self.assertEqual(exc.errno, errno.ENOSYS) self.assertFalse(lock.locked)
Example #11
Source File: test_lockfile.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_rmlinkError(self): """ An exception raised by L{rmlink} other than C{ENOENT} is passed up to the caller of L{FilesystemLock.lock}. """ def fakeRmlink(name): raise OSError(errno.ENOSYS, None) self.patch(lockfile, 'rmlink', fakeRmlink) def fakeKill(pid, signal): if signal != 0: raise OSError(errno.EPERM, None) if pid == 43125: raise OSError(errno.ESRCH, None) self.patch(lockfile, 'kill', fakeKill) lockf = self.mktemp() # Make it appear locked so it has to use readlink lockfile.symlink(str(43125), lockf) lock = lockfile.FilesystemLock(lockf) exc = self.assertRaises(OSError, lock.lock) self.assertEqual(exc.errno, errno.ENOSYS) self.assertFalse(lock.locked)
Example #12
Source File: _pslinux.py From teleport with Apache License 2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #13
Source File: _pslinux.py From teleport with Apache License 2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #14
Source File: _pslinux.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #15
Source File: _pslinux.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #16
Source File: _pslinux.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #17
Source File: _pslinux.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #18
Source File: _pslinux.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #19
Source File: semlock.py From loky with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _sem_open(name, value=None): """ Construct or retrieve a semaphore with the given name If value is None, try to retrieve an existing named semaphore. Else create a new semaphore with the given value """ if value is None: handle = pthread.sem_open(ctypes.c_char_p(name), 0) else: handle = pthread.sem_open(ctypes.c_char_p(name), SEM_OFLAG, SEM_PERM, ctypes.c_int(value)) if handle == SEM_FAILURE: e = ctypes.get_errno() if e == errno.EEXIST: raise FileExistsError("a semaphore named %s already exists" % name) elif e == errno.ENOENT: raise FileNotFoundError('cannot find semaphore named %s' % name) elif e == errno.ENOSYS: raise NotImplementedError('No semaphore implementation on this ' 'system') else: raiseFromErrno() return handle
Example #20
Source File: test_lockfile.py From learn_python3_spider with MIT License | 6 votes |
def test_rmlinkError(self): """ An exception raised by L{rmlink} other than C{ENOENT} is passed up to the caller of L{FilesystemLock.lock}. """ def fakeRmlink(name): raise OSError(errno.ENOSYS, None) self.patch(lockfile, 'rmlink', fakeRmlink) def fakeKill(pid, signal): if signal != 0: raise OSError(errno.EPERM, None) if pid == 43125: raise OSError(errno.ESRCH, None) self.patch(lockfile, 'kill', fakeKill) lockf = self.mktemp() # Make it appear locked so it has to use readlink lockfile.symlink(str(43125), lockf) lock = lockfile.FilesystemLock(lockf) exc = self.assertRaises(OSError, lock.lock) self.assertEqual(exc.errno, errno.ENOSYS) self.assertFalse(lock.locked)
Example #21
Source File: _pslinux.py From Galaxy_Plugin_Bethesda with MIT License | 6 votes |
def rlimit(self, resource, limits=None): # If pid is 0 prlimit() applies to the calling process and # we don't want that. We should never get here though as # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: if limits is None: # get return cext.linux_prlimit(self.pid, resource) else: # set if len(limits) != 2: raise ValueError( "second argument must be a (soft, hard) tuple, " "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: if err.errno == errno.ENOSYS and pid_exists(self.pid): # I saw this happening on Travis: # https://travis-ci.org/giampaolo/psutil/jobs/51368273 raise ZombieProcess(self.pid, self._name, self._ppid) else: raise
Example #22
Source File: test_lockfile.py From python-for-android with Apache License 2.0 | 5 votes |
def test_readlinkErrorPOSIX(self): """ Any L{IOError} raised by C{readlink} on a POSIX platform passed to the caller of L{FilesystemLock.lock}. On POSIX, unlike on Windows, these are unexpected errors which cannot be handled by L{FilesystemLock}. """ self._readlinkErrorTest(IOError, errno.ENOSYS) self._readlinkErrorTest(IOError, errno.EACCES)
Example #23
Source File: test_os.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_statvfs_attributes(self): try: result = os.statvfs(self.fname) except OSError, e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('glibc always returns ENOSYS on AtheOS') # Make sure direct access works
Example #24
Source File: multistore_file.py From luci-py with Apache License 2.0 | 5 votes |
def _lock(self): """Lock the entire multistore.""" self._thread_lock.acquire() try: self._file.open_and_lock() except IOError as e: if e.errno == errno.ENOSYS: logger.warn('File system does not support locking the ' 'credentials file.') elif e.errno == errno.ENOLCK: logger.warn('File system is out of resources for writing the ' 'credentials file (is your disk full?).') elif e.errno == errno.EDEADLK: logger.warn('Lock contention on multistore file, opening ' 'in read-only mode.') elif e.errno == errno.EACCES: logger.warn('Cannot access credentials file.') else: raise if not self._file.is_locked(): self._read_only = True if self._warn_on_readonly: logger.warn('The credentials file (%s) is not writable. ' 'Opening in read-only mode. Any refreshed ' 'credentials will only be ' 'valid for this run.', self._file.filename()) if os.path.getsize(self._file.filename()) == 0: logger.debug('Initializing empty multistore file') # The multistore is empty so write out an empty file. self._data = {} self._write() elif not self._read_only or self._data is None: # Only refresh the data if we are read/write or we haven't # cached the data yet. If we are readonly, we assume is isn't # changing out from under us and that we only have to read it # once. This prevents us from whacking any new access keys that # we have cached in memory but were unable to write out. self._refresh_data_cache()
Example #25
Source File: test_os.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_statvfs_attributes(self): if not hasattr(os, "statvfs"): return try: result = os.statvfs(self.fname) except OSError, e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: return # Make sure direct access works
Example #26
Source File: multistore_file.py From luci-py with Apache License 2.0 | 5 votes |
def _lock(self): """Lock the entire multistore.""" self._thread_lock.acquire() try: self._file.open_and_lock() except IOError as e: if e.errno == errno.ENOSYS: logger.warn('File system does not support locking the ' 'credentials file.') elif e.errno == errno.ENOLCK: logger.warn('File system is out of resources for writing the ' 'credentials file (is your disk full?).') elif e.errno == errno.EDEADLK: logger.warn('Lock contention on multistore file, opening ' 'in read-only mode.') elif e.errno == errno.EACCES: logger.warn('Cannot access credentials file.') else: raise if not self._file.is_locked(): self._read_only = True if self._warn_on_readonly: logger.warn('The credentials file (%s) is not writable. ' 'Opening in read-only mode. Any refreshed ' 'credentials will only be ' 'valid for this run.', self._file.filename()) if os.path.getsize(self._file.filename()) == 0: logger.debug('Initializing empty multistore file') # The multistore is empty so write out an empty file. self._data = {} self._write() elif not self._read_only or self._data is None: # Only refresh the data if we are read/write or we haven't # cached the data yet. If we are readonly, we assume is isn't # changing out from under us and that we only have to read it # once. This prevents us from whacking any new access keys that # we have cached in memory but were unable to write out. self._refresh_data_cache()
Example #27
Source File: multistore_file.py From luci-py with Apache License 2.0 | 5 votes |
def _lock(self): """Lock the entire multistore.""" self._thread_lock.acquire() try: self._file.open_and_lock() except IOError as e: if e.errno == errno.ENOSYS: logger.warn('File system does not support locking the ' 'credentials file.') elif e.errno == errno.ENOLCK: logger.warn('File system is out of resources for writing the ' 'credentials file (is your disk full?).') elif e.errno == errno.EDEADLK: logger.warn('Lock contention on multistore file, opening ' 'in read-only mode.') elif e.errno == errno.EACCES: logger.warn('Cannot access credentials file.') else: raise if not self._file.is_locked(): self._read_only = True if self._warn_on_readonly: logger.warn('The credentials file (%s) is not writable. ' 'Opening in read-only mode. Any refreshed ' 'credentials will only be ' 'valid for this run.', self._file.filename()) if os.path.getsize(self._file.filename()) == 0: logger.debug('Initializing empty multistore file') # The multistore is empty so write out an empty file. self._data = {} self._write() elif not self._read_only or self._data is None: # Only refresh the data if we are read/write or we haven't # cached the data yet. If we are readonly, we assume is isn't # changing out from under us and that we only have to read it # once. This prevents us from whacking any new access keys that # we have cached in memory but were unable to write out. self._refresh_data_cache()
Example #28
Source File: test_lockfile.py From learn_python3_spider with MIT License | 5 votes |
def test_readlinkError(self): """ An exception raised by C{readlink} other than C{ENOENT} is passed up to the caller of L{FilesystemLock.lock}. """ self._readlinkErrorTest(OSError, errno.ENOSYS) self._readlinkErrorTest(IOError, errno.ENOSYS)
Example #29
Source File: test_os.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_statvfs_attributes(self): if not hasattr(os, "statvfs"): return import statvfs try: result = os.statvfs(self.fname) except OSError, e: # On AtheOS, glibc always returns ENOSYS import errno if e.errno == errno.ENOSYS: return # Make sure direct access works
Example #30
Source File: multistore_file.py From luci-py with Apache License 2.0 | 5 votes |
def _lock(self): """Lock the entire multistore.""" self._thread_lock.acquire() try: self._file.open_and_lock() except IOError as e: if e.errno == errno.ENOSYS: logger.warn('File system does not support locking the ' 'credentials file.') elif e.errno == errno.ENOLCK: logger.warn('File system is out of resources for writing the ' 'credentials file (is your disk full?).') elif e.errno == errno.EDEADLK: logger.warn('Lock contention on multistore file, opening ' 'in read-only mode.') elif e.errno == errno.EACCES: logger.warn('Cannot access credentials file.') else: raise if not self._file.is_locked(): self._read_only = True if self._warn_on_readonly: logger.warn('The credentials file (%s) is not writable. ' 'Opening in read-only mode. Any refreshed ' 'credentials will only be ' 'valid for this run.', self._file.filename()) if os.path.getsize(self._file.filename()) == 0: logger.debug('Initializing empty multistore file') # The multistore is empty so write out an empty file. self._data = {} self._write() elif not self._read_only or self._data is None: # Only refresh the data if we are read/write or we haven't # cached the data yet. If we are readonly, we assume is isn't # changing out from under us and that we only have to read it # once. This prevents us from whacking any new access keys that # we have cached in memory but were unable to write out. self._refresh_data_cache()