Python Glossary Русский

all Python 3Linux · macOSsysfunction

sys.setdlopenflags()

interpreter

Sets the dlopen() flags for subsequent imports of C extension modules, for example os.RTLD_GLOBAL. Unix only (Linux, macOS).

Syntax

sys.setdlopenflags(n)

The flags affect only modules imported after the call: an already loaded extension is not loaded again. RTLD_GLOBAL exposes one extension's symbols to others but risks name clashes between libraries. Restore the old value right after the import that needed it. Windows lacks the function.

Examples

import os, sys
old = sys.getdlopenflags()
sys.setdlopenflags(old | os.RTLD_GLOBAL)
print(bool(sys.getdlopenflags() & os.RTLD_GLOBAL))  # → True
sys.setdlopenflags(old)
print(sys.getdlopenflags() == old)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy