1
1
/**********************************************************************
2
2
* plpython.c - python as a procedural language for PostgreSQL
3
3
*
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 $
5
5
*
6
6
*********************************************************************
7
7
*/
@@ -3206,6 +3206,8 @@ PyInit_plpy(void)
3206
3206
#endif
3207
3207
3208
3208
3209
+ static const int plpython_python_version = PY_MAJOR_VERSION ;
3210
+
3209
3211
/*
3210
3212
* _PG_init() - library load-time initialization
3211
3213
*
@@ -3216,6 +3218,21 @@ _PG_init(void)
3216
3218
{
3217
3219
/* Be sure we do initialization only once (should be redundant now) */
3218
3220
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
+ }
3219
3236
3220
3237
if (inited )
3221
3238
return ;
0 commit comments