diff --git a/README.md b/README.md index e679b533..9bc2fd43 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,17 @@ Or when you have question about MySQL/MariaDB: * [MySQL Support](https://dev.mysql.com/support/) * [Getting Help With MariaDB](https://mariadb.com/kb/en/getting-help-with-mariadb/) +## Free threading Python + +> [!NOTE] +> The support for Free threading Python is experimental. + +Since v2.2.8, free threading is supported when importing the extension module. Therefore, importing MySQLdb does not acquire GIL. + +However, this library does not support simultaneous operations on a single Connection object from multiple threads, regardless of free threading, and the behavior in such cases remains undefined. + +> [!WARNING] +> Do not use a single Connection object from multiple threads simultaneously. ## Install diff --git a/src/MySQLdb/_mysql.c b/src/MySQLdb/_mysql.c index cd95b641..30b111e5 100644 --- a/src/MySQLdb/_mysql.c +++ b/src/MySQLdb/_mysql.c @@ -2911,7 +2911,9 @@ PyInit__mysql(void) module = PyModule_Create(&_mysqlmodule); if (!module) return module; /* this really should never happen */ - +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); +#endif if (!(dict = PyModule_GetDict(module))) goto error; if (PyDict_SetItemString(dict, "version_info", PyRun_String(QUOTE(version_info), Py_eval_input,