0

I'm trying to create GIFs for every variable in a NetCDF file using the time dimension.

filepath = 'foam.nc'
variables = getVariables(filepath)

lat = getValue('lat', variables)[:]
lon = getValue('lon', variables)[:]

for var in keys:
    createGif(entity, lat, lon, t)

This works, but the process is taking a very long time (250 seconds). This NetCDF file contains 4 dimensions (time, hybrid, lat, long) with time having 9 depths.

Using the following example: https://stackoverflow.com/a/28463266/8166528 and https://stackoverflow.com/a/28975239/8166528, I tried to speed up the process using pool.map by giving every "createGif" a different thread, but I can't get it to work.

What I've tried:

entities = []
lats = []
lons = []
ts = []
for var in keys:
    entity = getValue(var, variables)
    entities.append(entity)
    lats.append(lat)
    lons.append(lon)
    ts.append(t)

pool = ThreadPool(8)
results = pool.starmap(createGif, zip(entities, lats, lons, ts))
pool.close()
pool.join()

Can someone point me in the right direction?

  • What issue are you having? Can you show output? BTW, what you have is multithreading which may not be appropriate if the code in createGif is python code. Will need to show complete example. – danny Jun 15 '17 at 16:53
  • Yes, createGif is python code. I get the following output: "RuntimeError: main thread is not in main loop". What code examples are you missing? – Thien Nguyen Jun 16 '17 at 09:56
  • Output with error and what output is expected to start with. How would one reproduce the error? The above is missing sample data as well as code for the `createGif` function. Have a look at instructions on creating a [Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve). – danny Jun 16 '17 at 10:23

0 Answers0