def _call_shared(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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 lock = EntropyResourcesLock(output=client_class) lock.acquire_shared() acquired = True client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _call_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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) lock.acquire_shared() acquired = True 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_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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) lock.acquire_shared() acquired = True 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()