def getrow(shpdata, rstdata, cols): drow = np.zeros((len(cols), )) lenght = len(shpdata) for i, rows in enumerate(zip(shpdata, *rstdata)): glg.G_percent(i, lenght, 2) start = 0 for row in rows: end = start + row.shape[0] # print('---') # for c, r in zip(cols[start:end], row): # print(c[0], r) drow[start:end] = row start = end # import ipdb; ipdb.set_trace() yield drow
def message_server(lock, conn): """The GRASS message server function designed to be a target for multiprocessing.Process :param lock: A multiprocessing.Lock :param conn: A multiprocessing.Pipe This function will use the G_* message C-functions from grass.lib.gis to provide an interface to the GRASS C-library messaging system. The data that is send through the pipe must provide an identifier string to specify which C-function should be called. The following identifers are supported: - "INFO" Prints an info message, see G_message() for details - "IMPORTANT" Prints an important info message, see G_important_message() for details - "VERBOSE" Prints a verbose message if the verbosity level is set accordingly, see G_verbose_message() for details - "WARNING" Prints a warning message, see G_warning() for details - "ERROR" Prints a message with a leading "ERROR: " string, see G_important_message() for details - "PERCENT" Prints a percent value based on three integer values: n, d and s see G_percent() for details - "STOP" Stops the server function and closes the pipe - "FATAL" Calls G_fatal_error(), this functions is only for testing purpose The that is end through the pipe must be a list of values: - Messages: ["INFO|VERBOSE|WARNING|ERROR|FATAL", "MESSAGE"] - Debug: ["DEBUG", level, "MESSAGE"] - Percent: ["PERCENT", n, d, s] """ libgis.G_debug(1, "Start messenger server") while True: # Avoid busy waiting conn.poll(None) data = conn.recv() message_type = data[0] # Only one process is allowed to write to stderr lock.acquire() # Stop the pipe and the infinite loop if message_type == "STOP": conn.close() lock.release() libgis.G_debug(1, "Stop messenger server") sys.exit() message = data[1] # libgis limitation if isinstance(message, type(" ")): if len(message) >= 2000: message = message[:1999] if message_type == "PERCENT": n = int(data[1]) d = int(data[2]) s = int(data[3]) libgis.G_percent(n, d, s) elif message_type == "DEBUG": level = data[1] message = data[2] libgis.G_debug(level, message) elif message_type == "VERBOSE": libgis.G_verbose_message(message) elif message_type == "INFO": libgis.G_message(message) elif message_type == "IMPORTANT": libgis.G_important_message(message) elif message_type == "WARNING": libgis.G_warning(message) elif message_type == "ERROR": libgis.G_important_message("ERROR: %s" % message) # This is for testing only elif message_type == "FATAL": libgis.G_fatal_error(message) lock.release()