bra...@closet.ten22  committed 22c2b55

Under Windows, only try to load the libzmq DLL if the file exists.

  • Participants
  • Parent commits e751847

Comments (0)

Files changed (1)

File zmq/

 import ctypes, os
 here = os.path.dirname(__file__)
 if sys.platform.startswith('win'):
-    library = os.path.join(here, 'libzmq.pyd')
-    libzmq = ctypes.cdll.LoadLibrary(library)
+    # In Windows the library might be a DLL or disguised as a Python
+    # extension.  If we cannot find either, we simply keep going without
+    # complaint, in the hope that the application has loaded it through
+    # some other mechanism.
+    libzmq = os.path.join(here, 'libzmq.dll')
+    if not os.path.exists(libzmq):
+        libzmq = os.path.join(here, 'libzmq.pyd')
+    if os.path.exists(libzmq):
+        ctypes.cdll.LoadLibrary(libzmq)
     # Under Linux, we cannot use "import" if we need the other extension
     # modules we load to be able to see symbols inside of "libzmq"; so
     # we load the shared library manually, using RTLD_GLOBAL.
-    library = os.path.join(here, '')
-    libzmq = ctypes.CDLL(library, mode=ctypes.RTLD_GLOBAL)
-del ctypes, os, here, library
+    libzmq = os.path.join(here, '')
+    ctypes.CDLL(libzmq, mode=ctypes.RTLD_GLOBAL)
+del here, libzmq, ctypes, os
 from zmq.utils import initthreads # initialize threads