Commit b579a335 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Poll frequently in StoppableThread

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