MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / checkSites

Method checkSites

src/File/FileServer.py:233–258  ·  view source on GitHub ↗
(self, check_files=False, force_port_check=False)

Source from the content-addressed store, hash-verified

231 # Check sites integrity
232 @util.Noparallel()
233 def checkSites(self, check_files=False, force_port_check=False):
234 self.log.debug("Checking sites...")
235 s = time.time()
236 sites_checking = False
237 if not self.port_opened or force_port_check: # Test and open port if not tested yet
238 if len(self.sites) <= 2: # Don't wait port opening on first startup
239 sites_checking = True
240 for address, site in list(self.sites.items()):
241 gevent.spawn(self.checkSite, site, check_files)
242
243 self.portCheck()
244
245 if not self.port_opened["ipv4"]:
246 self.tor_manager.startOnions()
247
248 if not sites_checking:
249 check_pool = gevent.pool.Pool(5)
250 # Check sites integrity
251 for site in sorted(list(self.sites.values()), key=lambda site: site.settings.get("modified", 0), reverse=True):
252 if not site.isServing():
253 continue
254 check_thread = check_pool.spawn(self.checkSite, site, check_files) # Check in new thread
255 time.sleep(2)
256 if site.settings.get("modified", 0) < time.time() - 60 * 60 * 24: # Not so active site, wait some sec to finish
257 check_thread.join(timeout=5)
258 self.log.debug("Checksites done in %.3fs" % (time.time() - s))
259
260 def cleanupSites(self):
261 import gc

Callers 1

wakeupWatcherMethod · 0.95

Calls 6

portCheckMethod · 0.95
itemsMethod · 0.80
startOnionsMethod · 0.80
valuesMethod · 0.80
isServingMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected