I am working on a system to import pre-generated SQL files with data to build PostGIS raster tables. The step which creates the SQL file seems to be working fine and I can manually import the SQL files, but the automated code halts during processing and never exits cleanly.
The import process in question has worked before on previous runs. The main change between then and now is the switch from using separate threads to process multiple runs at once to using the Python multiprocessing module for processing. However, the import process was working for a short time with multiprocessing implemented, and I am not sure exactly what changed to stop it from working.
The following method contains all of the import processing related code. The function is called by a parent object which handles the process management. The function is called within a wrapper function in the parent object which is spawned by Pythons multiprocessing.Process#start. The parameters meta and parent are a dictionary containing information necessary for the import and the parent object instance respectively.
The SQL file being used for import was generated in a previous step which also used Python subprocessing to execute the raster2pgsql command on a GeoTIFF file. The GeoTIFF is approximately 1.5GB.
def importSQL(meta, parent):
rasterId = meta['rasterId']
parent.conn.execute(queries.update_raster_state, ("Importing SQL", rasterId))
sqlFileName = meta['sqlFileName']
env = os.environ.copy()
env["PGPASSWORD"] = config.dbPassword()
#Import SQL file
log.info("importRaster#importSQL: Importing SQL to spatial table...")
psql = subprocess.Popen(("psql", "-f", sqlFileName, "-U", config.dbUser(), config.dbName()), stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
error = False
for errorLn in psql.stderr:
if "ERROR" in errorLn:
error = True
log.error(errorLn)
#psql.wait()
#Delete SQL file after complete
log.info("importRaster#importSQL: Cleaning directories.")
if os.path.exists(sqlFileName):
os.remove(sqlFileName)
return meta, not error
When it was functioning properly, the SQL import would run for a while, then the cleaning directories stage would post, and the function would return properly. There would also be a new table created from the import. Now, the process never exits. I watched top during processing and there was indeed a postgres process running at around 75% usage for several minutes, and then a dropoff in processing when the command presumably finished. However, after the processing dropoff on top, the process still does not continue to the cleaning directories stage and examination of the database shows that no new table was created.