解决python3.9连接数据库挂掉问题
This commit is contained in:
@ -1356,8 +1356,8 @@ register_type_uint(connectionObject *self, PyThreadState **tstate)
|
|||||||
}
|
}
|
||||||
if (typecast_add((PyObject *)obj, self->string_types, 0) < 0) { goto end; }
|
if (typecast_add((PyObject *)obj, self->string_types, 0) < 0) { goto end; }
|
||||||
rv = 0;
|
rv = 0;
|
||||||
free(_typecast_INTEGER_types);
|
|
||||||
end:
|
end:
|
||||||
|
free(_typecast_INTEGER_types);
|
||||||
Py_XDECREF(values);
|
Py_XDECREF(values);
|
||||||
Py_XDECREF(name);
|
Py_XDECREF(name);
|
||||||
return rv;
|
return rv;
|
||||||
@ -1428,15 +1428,26 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
|||||||
Dprintf("connection_setup: good connection object at %p, refcnt = "
|
Dprintf("connection_setup: good connection object at %p, refcnt = "
|
||||||
FORMAT_CODE_PY_SSIZE_T,
|
FORMAT_CODE_PY_SSIZE_T,
|
||||||
self, Py_REFCNT(self));
|
self, Py_REFCNT(self));
|
||||||
|
PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState));
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
sql_compatibility_value = pq_get_guc_locked(self, "sql_compatibility", &_save);
|
sql_compatibility_value = pq_get_guc_locked(self, "sql_compatibility", &_save);
|
||||||
set_sql_compatibility(self, sql_compatibility_value);
|
set_sql_compatibility(self, sql_compatibility_value);
|
||||||
if (register_type_uint(self, &_save)) { goto exit; }
|
memcpy(tstate, _save, sizeof(_save));
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&self->lock);
|
||||||
|
if (register_type_uint(self, &tstate)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (tstate) {
|
||||||
|
free(tstate);
|
||||||
|
tstate = NULL;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&self->lock);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (sql_compatibility_value){
|
if (sql_compatibility_value){
|
||||||
free(sql_compatibility_value);
|
free(sql_compatibility_value);
|
||||||
|
|||||||
Reference in New Issue
Block a user