From 8d0bcf9f823a77800940b091d05321aca93f0a4b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 25 Apr 2016 16:46:04 -0700 Subject: [PATCH] transcribe._sleep: make it usable from deallocate() If we're closing because of an error, we need to sleep through the old error, to be able to wait for the "deallocated" message. This might want to be different: maybe clear the error first, or store the errors in a list and sleep until a second error happens. --- src/wormhole/twisted/transcribe.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wormhole/twisted/transcribe.py b/src/wormhole/twisted/transcribe.py index c9f599c..cd3e9e7 100644 --- a/src/wormhole/twisted/transcribe.py +++ b/src/wormhole/twisted/transcribe.py @@ -181,13 +181,16 @@ class Wormhole: return self._signal_error(welcome["error"]) @inlineCallbacks - def _sleep(self): - if self._error: # don't sleep if the bed's already on fire + def _sleep(self, wake_on_error=True): + if wake_on_error and self._error: + # don't sleep if the bed's already on fire, unless we're waiting + # for the fire department to respond, in which case sure, keep on + # sleeping raise self._error d = defer.Deferred() self._sleepers.append(d) yield d - if self._error: + if wake_on_error and self._error: raise self._error def _wakeup(self):