diff -r 9397d2d76340 src/config.h.in
--- a/src/config.h.in	Wed Aug 11 23:37:32 2010 +0200
+++ b/src/config.h.in	Thu Aug 12 18:10:44 2010 +0200
@@ -343,6 +343,9 @@
 /* Define for linking via dlopen() or LoadLibrary() */
 #undef DYNAMIC_PYTHON3
 
+/* Define if dynamic python does not require RTLD_GLOBAL */
+#undef PY_NO_RTLD_GLOBAL
+
 /* Define if you want to include the Ruby interpreter. */
 #undef FEAT_RUBY
 
diff -r 9397d2d76340 src/configure.in
--- a/src/configure.in	Wed Aug 11 23:37:32 2010 +0200
+++ b/src/configure.in	Thu Aug 12 18:10:56 2010 +0200
@@ -757,10 +757,10 @@
 
 AC_MSG_CHECKING(--enable-pythoninterp argument)
 AC_ARG_ENABLE(pythoninterp,
-	[  --enable-pythoninterp   Include Python interpreter.], ,
+	[  --enable-pythoninterp[=OPTS]   Include Python interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
 	[enable_pythoninterp="no"])
 AC_MSG_RESULT($enable_pythoninterp)
-if test "$enable_pythoninterp" = "yes"; then
+if test "$enable_pythoninterp" = "yes" -o "$enable_pythoninterp" = "dynamic"; then
   dnl -- find the python executable
   AC_PATH_PROG(vi_cv_path_python, python)
   if test "X$vi_cv_path_python" != "X"; then
@@ -944,10 +944,10 @@
 
 AC_MSG_CHECKING(--enable-python3interp argument)
 AC_ARG_ENABLE(python3interp,
-	[  --enable-python3interp   Include Python3 interpreter.], ,
+	[  --enable-python3interp[=OPTS]   Include Python3 interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
 	[enable_python3interp="no"])
 AC_MSG_RESULT($enable_python3interp)
-if test "$enable_python3interp" = "yes"; then
+if test "$enable_python3interp" = "yes" -o "$enable_python3interp" = "dynamic"; then
   dnl -- find the python3 executable
   AC_PATH_PROG(vi_cv_path_python3, python3)
   if test "X$vi_cv_path_python3" != "X"; then
@@ -1109,6 +1109,46 @@
 if test "$python_ok" = yes && test "$python3_ok" = yes; then
   AC_DEFINE(DYNAMIC_PYTHON)
   AC_DEFINE(DYNAMIC_PYTHON3)
+  AC_MSG_CHECKING(whether we can do without RTLD_GLOBAL)
+  cflags_save=$CFLAGS
+  CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
+  ldflags_save=$LDFLAGS
+  LDFLAGS="$LDFLAGS -ldl"
+  AC_RUN_IFELSE([
+    #include <dlfcn.h>
+    /*If this program fails, then RTLD_GLOBAL is needed.
+    *RTLD_GLOBAL will be used and then it is not possible to
+    *have both python versions enabled in the same vim instance.
+    *Only the first pyhton version used will be switched on.
+    */
+
+    int no_rtl_global_needed_for(char *python_instsoname)
+    {
+      int needed = 0;
+      void* pylib = dlopen(python_instsoname, RTLD_LAZY);
+      if (pylib != 0)
+      {
+          void (*init)(void) = dlsym(pylib, "Py_Initialize");
+          int (*simple)(char*) = dlsym(pylib, "PyRun_SimpleString");
+          void (*final)(void) = dlsym(pylib, "Py_Finalize");
+          (*init)();
+          needed = (*simple)("import termios") == -1;
+          (*final)();
+          dlclose(pylib);
+      }
+      return !needed;
+    }
+
+    int main(int argc, char** argv)
+    {
+      int not_needed = 0;
+      if (no_rtl_global_needed_for("libpython2.7.so.1.0") && no_rtl_global_needed_for("libpython3.1.so.1.0"))
+            not_needed = 1;
+      return !not_needed;
+    }],
+    [AC_MSG_RESULT(yes);AC_DEFINE(PY_NO_RTLD_GLOBAL)], [AC_MSG_RESULT(no)])
+  CFLAGS=$cflags_save
+  LDFLAGS=$ldflags_save
   PYTHON_SRC="if_python.c"
   PYTHON_OBJ="objects/if_python.o"
   PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
@@ -1117,6 +1157,18 @@
   PYTHON3_OBJ="objects/if_python3.o"
   PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
   PYTHON3_LIBS=
+elif test "$python_ok" = yes && test "$enable_pythoninterp" = "dynamic"; then
+  AC_DEFINE(DYNAMIC_PYTHON)
+  PYTHON_SRC="if_python.c"
+  PYTHON_OBJ="objects/if_python.o"
+  PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
+  PYTHON_LIBS=
+elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
+  AC_DEFINE(DYNAMIC_PYTHON3)
+  PYTHON3_SRC="if_python3.c"
+  PYTHON3_OBJ="objects/if_python3.o"
+  PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
+  PYTHON3_LIBS=
 fi
 
 AC_MSG_CHECKING(--enable-tclinterp argument)
diff -r 9397d2d76340 src/if_python.c
--- a/src/if_python.c	Wed Aug 11 23:37:32 2010 +0200
+++ b/src/if_python.c	Thu Aug 12 18:11:05 2010 +0200
@@ -102,9 +102,7 @@
 #  include <dlfcn.h>
 #  define FARPROC void*
 #  define HINSTANCE void*
-#  ifdef FEAT_PYTHON3
-   /* Don't use RTLD_GLOBAL, it may cause a crash if both :python and :py3 are
-    * used. But without it importing may fail, e.g., for termios. */
+#  ifdef PY_NO_RTLD_GLOBAL
 #   define load_dll(n) dlopen((n), RTLD_LAZY)
 #  else
 #   define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -351,13 +349,15 @@
 {
     int i;
 
-#if 0  /* this should be OK now that we don't use RTLD_GLOBAL */
+#ifndef PY_NO_RTLD_GLOBAL
 #if defined(UNIX) && defined(FEAT_PYTHON3)
-    /* Can't have Python and Python3 loaded at the same time, it may cause a
-     * crash. */
+    /* Can't have Python and Python3 loaded at the same time. 
+     * It cause a crash, because RTLD_GLOBAL is needed for 
+     * standard C extension libraries of one or both python versions. 
+     */
     if (python3_loaded())
     {
-	EMSG(_("E999: Python: Cannot use :py and :py3 in one session"));
+	EMSG(_("Using :py and :py3 in one session disabled on this system"));
 	return FAIL;
     }
 #endif
diff -r 9397d2d76340 src/if_python3.c
--- a/src/if_python3.c	Wed Aug 11 23:37:32 2010 +0200
+++ b/src/if_python3.c	Thu Aug 12 18:11:13 2010 +0200
@@ -80,9 +80,7 @@
 #  include <dlfcn.h>
 #  define FARPROC void*
 #  define HINSTANCE void*
-#  ifdef FEAT_PYTHON
-   /* Don't use RTLD_GLOBAL, it may cause a crash if both :python and :py3 are
-    * used. But without it importing may fail, e.g., for termios. */
+#  ifdef PY_NO_RTLD_GLOBAL
 #   define load_dll(n) dlopen((n), RTLD_LAZY)
 #  else
 #   define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -338,13 +336,15 @@
     int i;
     void *ucs_from_string, *ucs_from_string_and_size;
 
-# if 0  /* this should be OK now that we don't use RTLD_GLOBAL */
+# ifndef PY_NO_RTLD_GLOBAL
 # if defined(UNIX) && defined(FEAT_PYTHON)
-    /* Can't have Python and Python3 loaded at the same time, it may cause a
-     * crash. */
+    /* Can't have Python and Python3 loaded at the same time. 
+     * It cause a crash, because RTLD_GLOBAL is needed for 
+     * standard C extension libraries of one or both python versions. 
+     */
     if (python_loaded())
     {
-	EMSG(_("E999: Python: Cannot use :py and :py3 in one session"));
+	EMSG(_("Using :py and :py3 in one session disabled on this system"));
 	return FAIL;
     }
 # endif
