Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
import MySQLdb
MySQLdb.connect接続できない場合があります。タイムアウトを設定して、アプリケーション固有のコードを記述せずにこれを繰り返し試行する方法はありますか?
MySQLdb.connect
接続コードを呼び出し可能なメソッドに抽象化し、接続を返すようにします。そのメソッド内で、データベースへの接続を最大3〜5回試行します。各試行の間にtime.sleep(.01)を実行します。それは100分の1秒です。あなたがより少なく行くことができれば、それはより良いでしょう。