Пример #1
0
	def tile(self, project: str, filename: str, truncate: bool = False) -> None:
		absolute_path = self.list.absolute_file_path(project, filename)
		ds = None
		if absolute_path is not "":
			try:
				lock = self.connections.dataset_locks.get(absolute_path)
				if lock is not None and lock.acquire(blocking=True, timeout=10):
					ds = LoomConnection(absolute_path, 'r')
					tiles = LoomTiles(ds)
					tiles.prepare_heatmap(truncate)
					ds.close()
					lock.release()
			except TimeoutError:
				# May happen when cancelled by the environment (for example, on a server).
				# If so, and the lock was acquired, release the dataset and lock
				if ds is not None:
					ds.close()
					lock.release()
				pass
Пример #2
0
	def connect(self, project: str, filename: str, mode: str="r+", timeout: float=10) -> LoomConnection:
		"""
		Try to connect to a local loom file. If returns None already connected.

		Uses a semaphore to ensure there is never more than one connection
		open to a loom file (as long as this is the only object that connects to the loom file)

		Remember to call `release(project, filename)` after closing the connection!

		Args:
			- project (string): 		Name of the project (e.g. "Midbrain")
			- filename (string): 		Filename of the loom file (e.g. "Midbrain_20160701.loom")

		Returns:
			A loom file connection, or None if file does not exist or was already connected.
		"""
		if self.acquire(project, filename, timeout):
			absolute_path = self.list.absolute_file_path(project, filename)
			return LoomConnection(absolute_path, mode)
		return None