You could use the MySQL Command, SHOW OPEN TABLES, to determine if there is a lock on a table. The in_use
column provides the number of table locks or lock requests for tables.
In which case, you could simply LOCK TABLES and UNLOCK TABLES
around queries that are expected to have a long execution time.