Flask - PyWSGI and concurrent access to dataset (netcdf) #5720
Replies: 3 comments 3 replies
-
Do you know if your data is stored in netCDF3 or netCDF4 files? If you're using netCDF3, the SciPy netCDF reader If you're using netCDF4, unfortunately the underlying HDF5 library is not threadsafe. In this case, there is no avoiding the use of a global locks for access within a single process. If you need to paralelize access to netCDF4 files, you'll need to make use of multiple processes. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I create the netcdf using xarray so i can change to NetCDF3_64BIT (it's 35 gb file) and see how it goes. Maybe i could create some processes on the controller and have user do some rest polling to get the result. |
Beta Was this translation helpful? Give feedback.
-
Although it might not answer your specific question, have you had a chance to look at https://github.com/xarray-contrib/xpublish ? It seems a good fit for what you would like to do. |
Beta Was this translation helpful? Give feedback.
-
Hello,
i have a NetCDF file which i would like to retrieve data from using a REST API. I have a python with flask restful with gevent pyWSGI server and applied monkey patching to allow concurrent requests on the same REST endpoint.
Each time a single request is executed, the NetCDF is opened as xarray dataset and data get extracted. But unfortunately when multiple concurrent requests are executed, xarray seems to handle them in sequential manner which i suspect occurs because it uses all available threads and flask-pywsgi cannot use another thread to serve the next request until the previous is finished.
Is there any workaround or a recommended practice to have multiple concurrent requests access the same netcdf dataset without having blocking behavior?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions