I use the Python multiprocessing module to speed up a geoprocessing function in my script. To this end, I use OGR, OSR and GDAL libraries. Multiprocessing works fine in Linux OS. However, when I execute the script in Windows OS, the multiprocessing.Process command doesn't start any function. Instead, I get the following error message, indicating that the OGR, OSR, and GDAL libraries (they are distributed in one package) are not found:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\ArcGIS10.4\lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
File "C:\Python27\ArcGIS10.4\lib\multiprocessing\forking.py", line 495, in prepare
'__parents_main__', file, path_name, etc
File "C:\Christian\Projects\2016-07 Geodesic Polygon Buffer\jo\Geodesic_Buffering_Areas18_2-Multicore.py", line 1, in <module>
import multiprocessing, ogr, osr
File "C:\Python27\ArcGIS10.4\lib\site-packages\ogr.py", line 2, in <module>
from osgeo.gdal import deprecation_warn
File "C:\Python27\ArcGIS10.4\lib\site-packages\osgeo\__init__.py", line 21, in<module>
_gdal = swig_import_helper()
File "C:\Python27\ArcGIS10.4\lib\site-packages\osgeo\__init__.py", line 17, inswig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified procedure could not be found.
This only happens when a function is called from p.start():
import multiprocessing, ogr, osr
def func(abc):
print abc
if __name__ == '__main__':
p = multiprocessing.Process(target = func, args=('xyz',))
p.start() # This is where I get the error
p.join()
When I run the script without importing the OGR and OSR libraries, func() is called from p.start() and I don't get any error messages. However, the import of both libraries works fine in the main section. The error message only shows up when multiprocessing calls a function.
Edit: Importing the libraries works outside multiprocessing:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ogr
>>> import osr
>>> import osgeo.gdal
>>> import multiprocessing
>>> import something
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named something
>>>
What is the reason for this error? Can this be related to forking? How can I use multiprocessing in Windows OS with OGR, OSR and GDAL libraries?
I use Python 2.7.10 (32 bit) in Windows and Python 2.7.6 (64 bit) in Linux.