-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Packet sequence number wrong #422
Comments
Please show me your code using PyMySQL. |
I can't provide the full code, but I can show you how I'm using PyMySQL:
All other queries in my code are just like these three. The only weird thing I can think of is maybe my connection code, however this worked fine in 0.6.6:
|
Is your application single thread? |
Ahh, it's multithreaded. Could this be the problem? Do I need one connection per thread? |
Yes. |
See https://www.python.org/dev/peps/pep-0249/#threadsafety PyMySQL's threadsafety is 1. |
Oops. My mistake! Didn't realize that. Makes sense. Thanks for all your help! |
Thanks for the issue, I finally fix my problem which fucked me these days! |
@EaconTang @dougty Can you please tell how did you fix it? |
@kadnan You need separate pymysql connections for each thread |
@dougty I am rather using
here Are you saying I explicitly call |
@kadnan Yes, you need one |
@dougty @ahmedsaalah I'v faced this problem before, then I created a module which provide connection pools in multi-threads mode. see here |
My suggestion is using existing robust system like SQLAlchemy's engine. |
SQLAlchemy also has this problem in multithread if you use one session,like this: # base.py
engine = create_engine(
get_db_str(),
echo=False,
pool_recycle=300,
poolclass=QueuePool,
pool_size=10,
max_overflow=10,
pool_timeout=30,
listeners=[Reconnect()]
)
Session = sessionmaker(bind=engine)
# user1.py
from .base import Session
session1 = Session()
session1.query
# user2.py
from .base import Session
session2 = Session()
session2.query I use ab command send 1000 requests to system. System raise that exception after some requests. |
I've been using PyMySQL 0.6.6 for a while now with no issues. However after updating to 0.7.1, I'm getting this error a lot, and PyMySQL has become completely unusable for me because of it.
The packet numbers vary, but I'm getting this for every query now, no matter how simple.
Things will work as expected for a few minutes after starting my script, but soon after these errors will begin appearing and no queries will work anymore.
I'm not sure if there's something I can do to resolve this in my script (some changes made in newer versions that I need to accommodate for) or if I should just figure out how to install the older version as a temporary solution. As it is now, this is a complete showstopper for me.
The text was updated successfully, but these errors were encountered: