diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-11-20 16:24:00 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-11-20 16:24:00 +0000 |
commit | 32090aee169aafc9da4efa176b50a5fc8ede68d2 (patch) | |
tree | c7606c2aecdce27c83e0e2dc95393a95761c7934 /synapse/util | |
parent | Merge branch 'master' into develop (diff) | |
download | synapse-32090aee169aafc9da4efa176b50a5fc8ede68d2.tar.xz |
Add a few missing yields, Move deferred lists inside PreserveLoggingContext because they don't interact well with the logging contexts
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/distributor.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/synapse/util/distributor.py b/synapse/util/distributor.py index eddbe5837f..701ccdb781 100644 --- a/synapse/util/distributor.py +++ b/synapse/util/distributor.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from synapse.util.logcontext import PreserveLoggingContext + from twisted.internet import defer import logging @@ -91,6 +93,7 @@ class Signal(object): Each observer callable may return a Deferred.""" self.observers.append(observer) + @defer.inlineCallbacks def fire(self, *args, **kwargs): """Invokes every callable in the observer list, passing in the args and kwargs. Exceptions thrown by observers are logged but ignored. It is @@ -98,22 +101,24 @@ class Signal(object): Returns a Deferred that will complete when all the observers have completed.""" - deferreds = [] - for observer in self.observers: - d = defer.maybeDeferred(observer, *args, **kwargs) - - def eb(failure): - logger.warning( - "%s signal observer %s failed: %r", - self.name, observer, failure, - exc_info=( - failure.type, - failure.value, - failure.getTracebackObject())) - if not self.suppress_failures: - raise failure - deferreds.append(d.addErrback(eb)) - - return defer.DeferredList( - deferreds, fireOnOneErrback=not self.suppress_failures - ) + with PreserveLoggingContext(): + deferreds = [] + for observer in self.observers: + d = defer.maybeDeferred(observer, *args, **kwargs) + + def eb(failure): + logger.warning( + "%s signal observer %s failed: %r", + self.name, observer, failure, + exc_info=( + failure.type, + failure.value, + failure.getTracebackObject())) + if not self.suppress_failures: + raise failure + deferreds.append(d.addErrback(eb)) + + result = yield defer.DeferredList( + deferreds, fireOnOneErrback=not self.suppress_failures + ) + defer.returnValue(result) |