douban / greenify

Make blocking C library work with gevent
BSD 3-Clause "New" or "Revised" License
430 stars 58 forks source link

请教一下如何patch mysqlclient? #18

Open sylvoslee opened 4 years ago

thehackercat commented 4 years ago

@sylvoslee 你好, 以 debian 下 mysqlclient==1.3.15 为例:

下列代码可以实现 patch mysqlclient

root@1a9a408a4e04:/# python
Python 2.7.18 (default, Apr 20 2020, 19:34:11)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from MySQLdb import _mysql
>>> _mysql_so = _mysql.__file__
>>> import greenify
>>> if greenify.patch_lib(_mysql_so):
...     print("Successfully patch mysql.so")
...
Successfully patch mysql.so
sylvoslee commented 4 years ago

我的是Ubuntu 16,按你提供的执行,greenify.patch_lib(_mysql_so)返回False,什么原因

thehackercat commented 4 years ago

可以提供下具体的环境吗,如

houzhiqiang commented 3 years ago

我执行也返回False,我是在python:3.8的docker容器里面 mysql 版本: mysql8 Debian(uname -a): Linux 03ed33a24640 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux cat /etc/debian_version: 10.6 python 版本: 3.8.6 mysql driver 路径: /usr/local/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-x86_64-linux-gnu.so mysqlclient 版本: 2.0.3

everpcpc commented 3 years ago

greenify 是将网络操作都 patch 掉,但是现在版本的 libmysqlclient-python 网络操作都在 libmysqlclient.so.18 里了,所以会 patch 失败。如果要正常 patch 的话,mysqlclient-python 需要静态链接: 将这里 https://github.com/PyMySQL/mysqlclient/blob/master/site.cfg#L3static = False 改成 True 再重新安装