Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the failure caused by pymysql non-thread safety

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to analyze the failure caused by pymysql non-thread safety. Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope everyone can gain something according to this article.

mysqldb This Python driver only supports Python 2 .

Go to Python 3. It's unusable.

Enable pymysql for this driver.

After putting into production, some problems were discovered.

In using larger-scale for id in [list]:

db.query (xxxxxxxxx)

Query database, there are some strange network connection level error.

The header byte of the datagram is in the wrong format.

No error is reported if only a single query is executed.

After investigation, it was found that this is a bug or defect of pymysql.

PYmysql is not thread safe. Thanks to our own component dba module.

Wrapper for database queries.

Causing in some cases. Python code optimization module.

For code optimization, there is a parallel situation.

That is, another thread starts and reads data from the same database handle when the previous sql query did not return.

This causes the format of the datagram to be incorrect.

Improvement programme:

1. Add thread locks to database connections.

Each query is locked. Unlocking codes are also added to exception handling.

2. Replace the official mysql-connector-python driver provided for mysql.com. No problems found at this time.

After reading the above, do you have any further understanding of how to analyze pymysql non-thread-safe failures? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report