Commit b579a335 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Poll frequently in StoppableThread

parent f54cf933
...@@ -334,16 +334,17 @@ class PithosFileClient(FileClient): ...@@ -334,16 +334,17 @@ class PithosFileClient(FileClient):
return dict((name, {"ident": None, "info": {}}) return dict((name, {"ident": None, "info": {}})
for name in newly_deleted_names) for name in newly_deleted_names)
def run_notifier(self):
candidates = self.get_pithos_candidates(
last_modified=self.last_modification)
with self.probe_candidates.lock() as d:
d.update(candidates)
def notifier(self): def notifier(self):
interval = self.settings.pithos_list_interval interval = self.settings.pithos_list_interval
class PollPithosThread(utils.StoppableThread): thread = utils.StoppableThread(interval, self.run_notifier)
def run_body(this): thread.start()
candidates = self.get_pithos_candidates( return thread
last_modified=self.last_modification)
with self.probe_candidates.lock() as d:
d.update(candidates)
time.sleep(interval)
return utils.start_daemon(PollPithosThread)
def get_object(self, objname): def get_object(self, objname):
try: try:
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import time
import threading import threading
import logging import logging
from collections import defaultdict from collections import defaultdict
...@@ -496,11 +495,9 @@ class FileSyncer(object): ...@@ -496,11 +495,9 @@ class FileSyncer(object):
self.probe_archive(self.SLAVE, forced=forced) self.probe_archive(self.SLAVE, forced=forced)
def _poll_decide(self, interval=3): def _poll_decide(self, interval=3):
class DecideThread(utils.StoppableThread): thread = utils.StoppableThread(interval, self.decide_all_archives)
def run_body(this): thread.start()
self.decide_all_archives() return thread
time.sleep(interval)
return utils.start_daemon(DecideThread)
def check_decisions(self): def check_decisions(self):
deciding = self.list_deciding() deciding = self.list_deciding()
......
...@@ -21,6 +21,7 @@ import watchdog.utils ...@@ -21,6 +21,7 @@ import watchdog.utils
import sys import sys
import logging import logging
import platform import platform
import time
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -113,21 +114,29 @@ BaseStoppableThread = watchdog.utils.BaseThread ...@@ -113,21 +114,29 @@ BaseStoppableThread = watchdog.utils.BaseThread
class StoppableThread(BaseStoppableThread): class StoppableThread(BaseStoppableThread):
def run_body(self): period = 0
step = 0
def run_body(self, period):
raise NotImplementedError() raise NotImplementedError()
def run(self): def run(self):
remaining = 0
while True: while True:
if not self.should_keep_running(): if not self.should_keep_running():
return return
self.run_body() if remaining <= 0:
remaining = self.period
self.run_body()
def start_daemon(threadClass): time.sleep(self.step)
thread = threadClass() remaining -= self.step
thread.daemon = True
thread.start() def __init__(self, period, target=None, step=0.1):
return thread BaseStoppableThread.__init__(self)
self.period = period
self.step = step
if target:
self.run_body = target
class ThreadSafeDict(object): class ThreadSafeDict(object):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment