Skip to content

Commit fe8e57d

Browse files
committed
free threading: do not enable GIL
1 parent d0371b2 commit fe8e57d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ Or when you have question about MySQL/MariaDB:
2121
* [MySQL Support](https://dev.mysql.com/support/)
2222
* [Getting Help With MariaDB](https://mariadb.com/kb/en/getting-help-with-mariadb/)
2323

24+
## Free threading Python
25+
26+
> [!NOTE]
27+
> The support for Free threading Python is experimental.
28+
29+
Since v2.2.8, free threading is supported when importing the extension module. Therefore, importing MySQLdb does not acquire GIL.
30+
31+
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.
32+
33+
> [!WARNING]
34+
> Do not use a single Connection object from multiple threads simultaneously.
2435
2536
## Install
2637

src/MySQLdb/_mysql.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,9 @@ PyInit__mysql(void)
29112911

29122912
module = PyModule_Create(&_mysqlmodule);
29132913
if (!module) return module; /* this really should never happen */
2914-
2914+
#ifdef Py_GIL_DISABLED
2915+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
2916+
#endif
29152917
if (!(dict = PyModule_GetDict(module))) goto error;
29162918
if (PyDict_SetItemString(dict, "version_info",
29172919
PyRun_String(QUOTE(version_info), Py_eval_input,

0 commit comments

Comments
 (0)