if self._pause_deferred is not None:
return
- # fired when the download is unpaused.
+ # fired when the download is unpaused.
self._old_status = self._status.get_status()
self._set_current_status("paused")
the Deferred fires immediately. Otherwise, the Deferred fires
when the downloader is unpaused.
"""
- if self._stopped:
- raise DownloadStopped("our Consumer called stopProducing()")
if self._pause_deferred is not None:
d = defer.Deferred()
self._pause_deferred.addCallback(lambda ignored: d.callback(res))
return d
- return defer.succeed(res)
+ return res
+
+ def _check_for_stopped(self, res):
+ if self._stopped:
+ raise DownloadStopped("our Consumer called stopProducing()")
+ return res
def download(self, consumer=None, offset=0, size=None):
# check to see whether we've been paused before writing
# anything.
d.addCallback(self._check_for_paused)
+ d.addCallback(self._check_for_stopped)
d.addCallback(self._set_segment)
return d
else:
from allmydata.immutable.downloader.status import DownloadStatus
from allmydata.immutable.downloader.fetcher import SegmentFetcher
from allmydata.codec import CRSDecoder
-from foolscap.eventual import fireEventually, flushEventualQueue
+from foolscap.eventual import eventually, fireEventually, flushEventualQueue
plaintext = "This is a moderate-sized file.\n" * 10
mutable_plaintext = "This is a moderate-sized mutable file.\n" * 10
self.producer.resumeProducing()
class PausingAndStoppingConsumer(PausingConsumer):
+ debug_stopped = False
def write(self, data):
+ if self.debug_stopped:
+ raise Exception("I'm stopped, don't write to me")
self.producer.pauseProducing()
- reactor.callLater(0.5, self._stop)
+ eventually(self._stop)
def _stop(self):
+ self.debug_stopped = True
self.producer.stopProducing()
class StoppingConsumer(PausingConsumer):