Merge pr337 from meejah:2218.fix-shutdown.0

closes tahoe-lafs/tahoe-lafs#337
This commit is contained in:
Brian Warner 2016-09-08 12:19:17 -07:00
commit ff82112b89

View File

@ -6,6 +6,7 @@ from datetime import datetime
import time
from twisted.internet import defer, reactor, task
from twisted.internet.error import AlreadyCancelled
from twisted.python.failure import Failure
from twisted.python import runtime
from twisted.python import log as twlog
@ -101,6 +102,9 @@ class MagicFolder(service.MultiService):
service.MultiService.startService(self)
return self.uploader.start_monitoring()
def stopService(self):
return self.finish()
def ready(self):
"""ready is used to signal us to start
processing the upload and download items...
@ -347,6 +351,7 @@ class Uploader(QueueMixin):
self._pending = set() # of unicode relpaths
self._periodic_full_scan_duration = 10 * 60 # perform a full scan every 10 minutes
self._periodic_callid = None
if hasattr(self._notifier, 'set_pending_delay'):
self._notifier.set_pending_delay(pending_delay)
@ -377,7 +382,12 @@ class Uploader(QueueMixin):
self._stopped = True
self._notifier.stopReading()
self._count('dirs_monitored', -1)
self.periodic_callid.cancel()
if self._periodic_callid:
try:
self._periodic_callid.cancel()
except AlreadyCancelled:
pass
if hasattr(self._notifier, 'wait_until_stopped'):
d = self._notifier.wait_until_stopped()
else:
@ -402,7 +412,7 @@ class Uploader(QueueMixin):
return self._begin_processing(None)
def _full_scan(self):
self.periodic_callid = self._clock.callLater(self._periodic_full_scan_duration, self._full_scan)
self._periodic_callid = self._clock.callLater(self._periodic_full_scan_duration, self._full_scan)
self._log("FULL SCAN")
self._log("_pending %r" % (self._pending))
self._scan(u"")