~lifeless/storm/bug-619017

« back to all changes in this revision

Viewing changes to storm/tracer.py

Merged better-timeout-messages [r=lifeless,mwhudson] [f=617973]

When a TimeoutError is raised it now includes a description
explaining how the exception was triggered.  This should help make
it easier to reason about timeout-related issues.  Several
docstrings related to timeout tracing machinery have been added or
improved, as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
 
41
41
class TimeoutTracer(object):
 
42
    """Provide a timeout facility for connections to prevent rogue operations.
 
43
 
 
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.
 
47
    """
42
48
 
43
49
    def __init__(self, granularity=5):
44
50
        self.granularity = granularity
45
51
 
46
 
    def connection_raw_execute(self, connection, raw_cursor, statement, params):
 
52
    def connection_raw_execute(self, connection, raw_cursor, statement,
 
53
                               params):
 
54
        """Check timeout conditions before a statement is executed.
 
55
 
 
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
 
61
            execute C{statement}.
 
62
        """
47
63
        remaining_time = self.get_remaining_time()
48
64
        if remaining_time <= 0:
49
 
            raise TimeoutError(statement, params)
 
65
            raise TimeoutError(
 
66
                "%d seconds remaining in time budget" % remaining_time,
 
67
                statement, params)
50
68
 
51
69
        last_remaining_time = getattr(connection,
52
70
                                      "_timeout_tracer_remaining_time", 0)