0

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.

C.Riedel
  • 3
  • 4
  • it looks like a duplicate of [this question](http://stackoverflow.com/q/6009506/6719428), I mean the traceback shows the same errors – odrling Aug 23 '16 at 13:16
  • The question in your link deals with the installation of GDAL. This has worked for me. I don't get any error messages from "import ogr". I only get error messages when starting multiprocessing.Process(). – C.Riedel Aug 23 '16 at 13:25
  • Well the traceback clearly shows that there is a problem with your installation, and from what I can see you should get the same error just by importing osgeo.gdal – odrling Aug 23 '16 at 13:30
  • Is the result the same if you move ``import ogr, osr`` to inside ``def func()`` ? – codeape Aug 23 '16 at 14:29
  • Yes, the error is the same. The only difference is a `Process Process-1:` at the beginning of the error message. – C.Riedel Aug 23 '16 at 14:54

0 Answers0