FileServer: move loadTrackersFile() to a separate thread

This commit is contained in:
Vadim Ushakov 2020-10-28 17:56:11 +07:00
parent 112c778c28
commit 3ca323f8b0

View file

@ -318,11 +318,21 @@ class FileServer(ConnectionServer):
site.sendMyHashfield(3) site.sendMyHashfield(3)
site.updateHashfield(3) site.updateHashfield(3)
# Periodic reloading of tracker files
def reloadTrackerFilesThread(self):
# TODO:
# This should probably be more sophisticated.
# We should check if the files have actually changed,
# and do it more often.
interval = 60 * 10
while 1:
time.sleep(interval)
config.loadTrackersFile()
# Announce sites every 20 min # Announce sites every 20 min
def announceSites(self): def announceSites(self):
time.sleep(5 * 60) # Sites already announced on startup time.sleep(5 * 60) # Sites already announced on startup
while 1: while 1:
config.loadTrackersFile()
s = time.time() s = time.time()
for address, site in list(self.sites.items()): for address, site in list(self.sites.items()):
if not site.isServing(): if not site.isServing():
@ -387,6 +397,7 @@ class FileServer(ConnectionServer):
if check_sites: # Open port, Update sites, Check files integrity if check_sites: # Open port, Update sites, Check files integrity
gevent.spawn(self.checkSites) gevent.spawn(self.checkSites)
thread_reaload_tracker_files = gevent.spawn(self.reloadTrackerFilesThread)
thread_announce_sites = gevent.spawn(self.announceSites) thread_announce_sites = gevent.spawn(self.announceSites)
thread_cleanup_sites = gevent.spawn(self.cleanupSites) thread_cleanup_sites = gevent.spawn(self.cleanupSites)
thread_wakeup_watcher = gevent.spawn(self.wakeupWatcher) thread_wakeup_watcher = gevent.spawn(self.wakeupWatcher)