This is a fork of mysqlclient to support gevent. The purpose is to get the speed of a mysql C-library within a gevent application, but without the need to use a thread-pool.
This is achieved by modifying mysql.c
to use the
non blocking API of libmariadb
.
This API allows to customize the waiting for read/write events on a socket.
gevent_mysql uses gevent.socket.wait_read
and gevent.socket.wait_write
to do so.
-
The destructor for a
_mysql.Connection
does not happen in a non-blocking way when the connection is still open. In that case the destructor calls implicitlymysql_close()
wich cannot be done in gevent friendly way. Since switching a greenlet in the code path of garbage collection is dangerous. Image the garbage collection is run by the hub greenlet. Then the hub would switch to himself, which is not possible. Recommendation: Callconn.close()
always explicitly. -
The destructor of
_mysql.result
could block other greenlets under the following circumstances.- The result object was acquired via
conn.use_result()
. - Not all rows from the result have been read by the application.
conn.use_result()
gives a lazy result back. In case the application did not consume all rows from this result the mysql-driver has to discard the remaining rows. This discard (and all the involved network IO) does not happen in a non-blocking way. Recommendation is to useconn.store_result()
. This applies also forMySQLdb.SSCursor
andMySQLdb.CursorUseResultMixIn
, because the useconn.use_result()
under the hood. - The result object was acquired via
This project is a fork of MySQLdb1. This project adds Python 3 support and fixed many bugs.
Do Not use Github Issue Tracker to ask help. OSS Maintainer is not free tech support
When your question looks relating to Python rather than MySQL:
- Python mailing list python-list
- Slack pythondev.slack.com
Or when you have question about MySQL:
gevent_mysqldb hasn't been tested/build on windows yet.
If binary wheels do not exist for your version of Python, it may be possible to
build from source, but if this does not work, do not come asking for support.
To build from source, download the
MariaDB C Connector and install
it. It must be installed in the default location
(usually "C:\Program Files\MariaDB\MariaDB Connector C" or
"C:\Program Files (x86)\MariaDB\MariaDB Connector C" for 32-bit). If you
build the connector yourself or install it in a different location, set the
environment variable MYSQLCLIENT_CONNECTOR
before installing. Once you have
the connector installed and an appropriate version of Visual Studio for your
version of Python:
$ pip install mysqlclient
gevent_mysqldb hasn't been tested/build on macOS yet.
Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a issue on the issue tracker.
You may need to install the Python 3 and libmariadb development headers and libraries
sudo apt-get install python3-setuptools python3-dev build-essential python3-gevent libmariadb-dev-compat
sudo dnf install python3-setuptools python3-devel python3-gevent gcc-c++ mariadb-connector-c-devel
sudo yum install python3-setuptools python3-devel python3-gevent gcc-c++ mariadb-connector-c-devel mariadb-devel
Then you can install gevent_mysqldb via pip now:
pip3 install git+https://github.com/axiros/gevent_mysqldb.git
mysqlclient uses mysql_config
or mariadb_config
by default for finding
compiler/linker flags.
You can use MYSQLCLIENT_CFLAGS
and MYSQLCLIENT_LDFLAGS
environment
variables to customize compiler/linker options.
$ export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
$ export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`
$ pip install mysqlclient
Documentation is hosted on Read The Docs