def acquire(self): """ Overridden from BaseBinaryResourceLock. """ lock = EntropyResourcesLock(output=Server) if self._blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: raise EntropyResourceLock.NotAcquired("unable to acquire lock")
def acquire(self): """ Overridden from BaseBinaryResourceLock. """ lock = EntropyResourcesLock(output=Server) if self._blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: raise EntropyResourceLock.NotAcquired( "unable to acquire lock")
def _call_exclusive(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None server_class = None acquired = False lock = None # make possible to avoid dealing with the resources lock. # This is useful if the lock is already acquired by some # parent or controller process. skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 if not skip_lock: lock = EntropyResourcesLock(output=server_class) acquired = lock.wait_exclusive() if not acquired: server_class.output(darkgreen( _("Another Entropy is currently running.")), level="error", importance=1) return 1 server = server_class(default_repository=repo) # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: lock.release()
def _call_exclusive(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None server_class = None acquired = False lock = None # make possible to avoid dealing with the resources lock. # This is useful if the lock is already acquired by some # parent or controller process. skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 if not skip_lock: lock = EntropyResourcesLock(output=server_class) acquired = lock.wait_exclusive() if not acquired: server_class.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 server = server_class(default_repository=repo) # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: lock.release()
def _call_exclusive(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_client). """ client_class = None client = None acquired = False lock = None try: try: client_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 blocking = os.getenv("__EQUO_LOCKS_BLOCKING__") if blocking: client_class.output(darkgreen( _("Acquiring Entropy Resources " "Lock, please wait...")), back=True) lock = EntropyResourcesLock(output=client_class) if blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: client_class.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _call_exclusive(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_client). """ client_class = None client = None acquired = False lock = None try: try: client_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 blocking = os.getenv("__EQUO_LOCKS_BLOCKING__") if blocking: client_class.output(darkgreen( _("Acquiring Entropy Resources " "Lock, please wait...")), back=True) lock = EntropyResourcesLock(output=client_class) if blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: client_class.output(darkgreen( _("Another Entropy is currently running.")), level="error", importance=1) return 1 client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()