11/**********************************************************************
22 * plpython.c - python as a procedural language for PostgreSQL
33 *
4- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.146 2010/07/06 19:19:01 momjian Exp $
4+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.147 2010/07/08 18:42:12 petere Exp $
55 *
66 *********************************************************************
77 */
@@ -3206,6 +3206,8 @@ PyInit_plpy(void)
32063206#endif
32073207
32083208
3209+ static const int plpython_python_version = PY_MAJOR_VERSION ;
3210+
32093211/*
32103212 * _PG_init() - library load-time initialization
32113213 *
@@ -3216,6 +3218,21 @@ _PG_init(void)
32163218{
32173219 /* Be sure we do initialization only once (should be redundant now) */
32183220 static bool inited = false;
3221+ const int * * version_ptr ;
3222+
3223+ /* Be sure we don't run Python 2 and 3 in the same session (might crash) */
3224+ version_ptr = (const int * * ) find_rendezvous_variable ("plpython_python_version" );
3225+ if (!(* version_ptr ))
3226+ * version_ptr = & plpython_python_version ;
3227+ else
3228+ {
3229+ if (* * version_ptr != plpython_python_version )
3230+ ereport (FATAL ,
3231+ (errmsg ("Python major version mismatch in session" ),
3232+ errdetail ("This session has previously used Python major version %d, and it is now attempting to use Python major version %d." ,
3233+ * * version_ptr , plpython_python_version ),
3234+ errhint ("Start a new session to use a different Python major version." )));
3235+ }
32193236
32203237 if (inited )
32213238 return ;
0 commit comments