Pymysql encountered a pit, after updating the data, re-reading the field data is not updated.

Write a small script and prepare to use MySQL as the database. Redis has not learned well, so I don't want to use it.

The logic is this, I look for a piece of data here, if this data exists, assign the attribute, if it does not exist, execute the task and write it to the database.

Then perform the search data again and write the object attributes.

  # Initialize the user's uid, uid can read 
    def _initialize_uid (self) from the user's income database table : 
        # When reading and writing, you need to reconnect to the database to ensure that the data read is new 
        uid_info = self.db.selectDb (SEARCH_USER_UID, (self.account,)) 
        # If it cannot be read, execute the user's income statement and new data. 
        if uid_info: 
            self.uid = uid_info [0] [0] 
        else: 
            print (123) 
        # write database information, if get_money_income (self.account) [0]: time.sleep (2)
          # re-execute the method to read Get data self._initialize_uid ()

 If your database maintains a consistent link, I found that using this recursive model I could not read the database information of the written data. There is no good way for now.

The only solution is to create a new connection object every time you search, but in this case, you will feel more pressure on the database.

 

In the future, I also use too many threads for database operations, similar to the relationship between producers and consumers. Remember one write, one read can read the database and the new one. Is it possible for a single thread to write itself, and reading the written data cannot be completed ?

In this case, it feels very troublesome to use. Follow up to find out if there is any solution

Guess you like

Origin www.cnblogs.com/sidianok/p/12727409.html