Anonymous avatar Anonymous committed 22c2b55

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

Comments (0)

Files changed (1)

 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.