0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 18:23:58 +01:00

Fix pep8 warnings.

This commit is contained in:
Mark Haines 2015-10-13 17:18:29 +01:00
parent 7639c3d9e5
commit 32d66738b0

View file

@ -17,13 +17,6 @@ from twisted.internet import defer, reactor
from functools import wraps from functools import wraps
from synapse.util.logcontext import LoggingContext, PreserveLoggingContext from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
def with_logging_context(fn):
context = LoggingContext.current_context()
def restore_context_callback(x):
with PreserveLoggingContext():
LoggingContext.thread_local.current_context = context
return fn(x)
return restore_context_callback
def debug_deferreds(): def debug_deferreds():
"""Cause all deferreds to wait for a reactor tick before running their """Cause all deferreds to wait for a reactor tick before running their
@ -31,6 +24,18 @@ def debug_deferreds():
a defer.inlineCallback since the code waiting on the deferred will get a defer.inlineCallback since the code waiting on the deferred will get
a chance to add an errback before the deferred runs.""" a chance to add an errback before the deferred runs."""
# Helper method for retrieving and restoring the current logging context
# around a callback.
def with_logging_context(fn):
context = LoggingContext.current_context()
def restore_context_callback(x):
with PreserveLoggingContext():
LoggingContext.thread_local.current_context = context
return fn(x)
return restore_context_callback
# We are going to modify the __init__ method of defer.Deferred so we # We are going to modify the __init__ method of defer.Deferred so we
# need to get a copy of the old method so we can still call it. # need to get a copy of the old method so we can still call it.
old__init__ = defer.Deferred.__init__ old__init__ = defer.Deferred.__init__
@ -65,4 +70,3 @@ def debug_deferreds():
self.addCallbacks(bounce_callback, bounce_errback) self.addCallbacks(bounce_callback, bounce_errback)
defer.Deferred.__init__ = new__init__ defer.Deferred.__init__ = new__init__