On startup don't run more than 5 checkSite at the same time
This commit is contained in:
parent
ee97eb6d27
commit
3a9ded9315
1 changed files with 5 additions and 1 deletions
|
@ -6,6 +6,7 @@ import random
|
|||
import socket
|
||||
|
||||
import gevent
|
||||
import gevent.pool
|
||||
|
||||
import util
|
||||
from Config import config
|
||||
|
@ -263,6 +264,7 @@ class FileServer(ConnectionServer):
|
|||
@util.Noparallel()
|
||||
def checkSites(self, check_files=False, force_port_check=False):
|
||||
self.log.debug("Checking sites...")
|
||||
s = time.time()
|
||||
sites_checking = False
|
||||
if self.port_opened is None or force_port_check: # Test and open port if not tested yet
|
||||
if len(self.sites) <= 2: # Don't wait port opening on first startup
|
||||
|
@ -277,11 +279,13 @@ class FileServer(ConnectionServer):
|
|||
self.tor_manager.startOnions()
|
||||
|
||||
if not sites_checking:
|
||||
check_pool = gevent.pool.Pool(5)
|
||||
for site in sorted(self.sites.values(), key=lambda site: site.settings.get("modified", 0), reverse=True): # Check sites integrity
|
||||
check_thread = gevent.spawn(self.checkSite, site, check_files) # Check in new thread
|
||||
check_thread = check_pool.spawn(self.checkSite, site, check_files) # Check in new thread
|
||||
time.sleep(2)
|
||||
if site.settings.get("modified", 0) < time.time() - 60 * 60 * 24: # Not so active site, wait some sec to finish
|
||||
check_thread.join(timeout=5)
|
||||
self.log.debug("Checksites done in %.3fs" % (time.time() - s))
|
||||
|
||||
def cleanupSites(self):
|
||||
import gc
|
||||
|
|
Loading…
Reference in a new issue