The code is a step-by-step copy from the sqlahcmey orm tutorial , with the exception of the last line, I decided to delete all the tables after the query. But the program blocked on Base.metadata.drop_all(bind=engine) below is the MySQL status at that time (taken from MySQL Workbench):

As the marked line shows, the drag and drop table process was hung up due to table metadata lock , I suggest that metadata lock was called result = session.query(User).all() , because the program did not block if this line was deleted, but I still donβt know the reason. So my question is: why did this happen, how to avoid blocking
Reorx
source share