__init__.py 940 B

12345678910111213141516171819202122232425262728293031323334
  1. """Import basic exposure of libzmq C API as a backend"""
  2. # Copyright (C) PyZMQ Developers
  3. # Distributed under the terms of the Modified BSD License.
  4. import os
  5. import platform
  6. from .select import public_api, select_backend
  7. if 'PYZMQ_BACKEND' in os.environ:
  8. backend = os.environ['PYZMQ_BACKEND']
  9. if backend in ('cython', 'cffi'):
  10. backend = f'zmq.backend.{backend}'
  11. _ns = select_backend(backend)
  12. else:
  13. # default to cython, fallback to cffi
  14. # (reverse on PyPy)
  15. if platform.python_implementation() == 'PyPy':
  16. first, second = ('zmq.backend.cffi', 'zmq.backend.cython')
  17. else:
  18. first, second = ('zmq.backend.cython', 'zmq.backend.cffi')
  19. try:
  20. _ns = select_backend(first)
  21. except Exception as original_error:
  22. try:
  23. _ns = select_backend(second)
  24. except ImportError:
  25. raise original_error from None
  26. globals().update(_ns)
  27. __all__ = public_api