41
41
class TimeoutTracer(object):
42
"""Provide a timeout facility for connections to prevent rogue operations.
44
This tracer must be subclassed by backend-specific implementations that
45
override C{connection_raw_execute_error}, C{set_statement_timeout} and
46
C{get_remaining_time} methods.
43
49
def __init__(self, granularity=5):
44
50
self.granularity = granularity
46
def connection_raw_execute(self, connection, raw_cursor, statement, params):
52
def connection_raw_execute(self, connection, raw_cursor, statement,
54
"""Check timeout conditions before a statement is executed.
56
@param connection: The L{Connection} to the database.
57
@param raw_cursor: A cursor object, specific to the backend being used.
58
@param statement: The SQL statement to execute.
59
@param params: The parameters to use with C{statement}.
60
@raises TimeoutError: Raised if there isn't enough time left to
47
63
remaining_time = self.get_remaining_time()
48
64
if remaining_time <= 0:
49
raise TimeoutError(statement, params)
66
"%d seconds remaining in time budget" % remaining_time,
51
69
last_remaining_time = getattr(connection,
52
70
"_timeout_tracer_remaining_time", 0)