summary refs log tree commit diff
path: root/synapse/util/__init__.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-05-12 15:23:50 +0100
committerMark Haines <mjark@negativecurvature.net>2015-05-12 15:23:50 +0100
commita6fb2aa2a5a5837d77bed8813f9e59bfe6be8999 (patch)
tree154ff4598b9740104abd5cf465c98cf2797c5406 /synapse/util/__init__.py
parentMerge pull request #149 from matrix-org/erikj/backfill (diff)
parentMake distributer.fire work as it did (diff)
downloadsynapse-a6fb2aa2a5a5837d77bed8813f9e59bfe6be8999.tar.xz
Merge pull request #144 from matrix-org/erikj/logging_context
Preserving logging contexts
Diffstat (limited to 'synapse/util/__init__.py')
-rw-r--r--synapse/util/__init__.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py

index 79109d0b19..c1a16b639a 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py
@@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from synapse.util.logcontext import LoggingContext +from synapse.util.logcontext import LoggingContext, PreserveLoggingContext from twisted.internet import defer, reactor, task @@ -23,6 +23,12 @@ import logging logger = logging.getLogger(__name__) +def unwrapFirstError(failure): + # defer.gatherResults and DeferredLists wrap failures. + failure.trap(defer.FirstError) + return failure.value.subFailure + + class Clock(object): """A small utility that obtains current time-of-day so that time may be mocked during unit-tests. @@ -50,9 +56,12 @@ class Clock(object): current_context = LoggingContext.current_context() def wrapped_callback(): - LoggingContext.thread_local.current_context = current_context - callback() - return reactor.callLater(delay, wrapped_callback) + with PreserveLoggingContext(): + LoggingContext.thread_local.current_context = current_context + callback() + + with PreserveLoggingContext(): + return reactor.callLater(delay, wrapped_callback) def cancel_call_later(self, timer): timer.cancel()