is there a pythonic way to try something up to a maximum number of times?
问题 I have a python script which is querying a MySQL server on a shared linux host. For some reason, queries to MySQL often return a "server has gone away" error: _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') If you try the query again immediately afterwards, it usually succeeds. So, I'd like to know if there's a sensible way in python to try to execute a query, and if it fails, to try again, up to a fixed number of tries. Probably I'd want it to try 5 times before