try:
    return TimeLimited(cursor.execute, timeout)(query_string, *query_args)
except TimeLimitExpired:
    logger_ec.error('%s; Timeout error.' % log_msg)
Django: How can you stop long queries from killing your database?