Latest Version: 0.9.6.2

StackedObjectRestorer

Track StackedObjectProxies and their proxied objects for automatic restoration within EvalException's interactive debugger.

An instance of this class tracks all StackedObjectProxy state in existence when unexpected exceptions are raised by WSGI applications housed by EvalException and RegistryManager. Like EvalException, this information is stored for the life of the process.

When an unexpected exception occurs and EvalException is present in the WSGI stack, save_registry_state is intended to be called to store the Registry state and enable automatic restoration on all currently registered StackedObjectProxies.

With restoration enabled, those StackedObjectProxies' _current_obj (overwritten by _current_obj_restoration) method's strategy is modified: it will return its appropriate proxied object from the restorer when a restoration context is active in the current thread.

The StackedObjectProxies' _push/pop_object methods strategies are also changed: they no-op when a restoration context is active in the current thread (because the pushing/popping work is all handled by the Registry/restorer).

The request's Registry objects' reglists are restored from the restorer when a restoration context begins, enabling the Registry methods to work while their changes are tracked by the restorer.

The overhead of enabling restoration is negligible (another threadlocal access for the changed StackedObjectProxy methods) for normal use outside of a restoration context, but worth mentioning when combined with StackedObjectProxies normal overhead. Once enabled it does not turn off, however:

o Enabling restoration only occurs after an unexpected exception is detected. The server is likely to be restarted shortly after the exception is raised to fix the cause

o StackedObjectRestorer is only enabled when EvalException is enabled (not on a production server) and RegistryManager exists in the middleware stack


Methods

f __init__(self) ...

f enable_restoration(self, stacked) ...

Replace the specified StackedObjectProxy's methods with their respective restoration versions.

_current_obj_restoration forces recovery of the saved proxied object when a restoration context is active in the current thread.

_push/pop_object_restoration avoid pushing/popping data (pushing/popping is only done at the Registry level) when a restoration context is active in the current thread

f get_request_id(self, environ) ...

Return a unique identifier for the current request

f get_saved_proxied_obj(self, stacked, request_id) ...

Retrieve the saved object proxied by the specified StackedObjectProxy for the request identified by request_id

f in_restoration(self) ...

Determine if a restoration context is active for the current thread. Returns the request_id it's active for if so, otherwise False

f restoration_begin(self, request_id) ...

Enable a restoration context in the current thread for the specified request_id

f restoration_end(self) ...

Register a restoration context as finished, if one exists

f save_registry_state(self, environ) ...

Save the state of this request's Registry (if it hasn't already been saved) to the saved_registry_states dict, keyed by the request's unique identifier

See the source for more information.

Top