limitations and irc to readme, version 0.1.2, socket debugging option, Notify exceptions support, better error logging, retry on socket error, dont expose external ip to websocket api, kill workers if no task, log time to console
This commit is contained in:
parent
185424b815
commit
b37e309eda
14 changed files with 136 additions and 68 deletions
|
@ -1,5 +1,6 @@
|
|||
import gevent, time, logging, shutil, os
|
||||
from Peer import Peer
|
||||
from Debug import Debug
|
||||
|
||||
class Worker:
|
||||
def __init__(self, manager, peer):
|
||||
|
@ -66,6 +67,11 @@ class Worker:
|
|||
self.running = True
|
||||
self.thread = gevent.spawn(self.downloader)
|
||||
|
||||
|
||||
# Force stop the worker
|
||||
def stop(self):
|
||||
self.manager.log.debug("%s: Force stopping, thread: %s" % (self.key, self.thread))
|
||||
self.running = False
|
||||
if self.thread:
|
||||
self.thread.kill(exception=Debug.Notify("Worker stopped"))
|
||||
self.manager.removeWorker(self)
|
||||
|
|
|
@ -16,7 +16,12 @@ class WorkerManager:
|
|||
# Check expired tasks
|
||||
def checkTasks(self):
|
||||
while 1:
|
||||
time.sleep(15) # Check every 30 sec
|
||||
time.sleep(15) # Check every 15 sec
|
||||
|
||||
# Clean up workers
|
||||
if not self.tasks and self.workers: # No task but workers still running
|
||||
for worker in self.workers.values(): worker.stop()
|
||||
|
||||
if not self.tasks: continue
|
||||
tasks = self.tasks[:] # Copy it so removing elements wont cause any problem
|
||||
for task in tasks:
|
||||
|
@ -40,6 +45,7 @@ class WorkerManager:
|
|||
|
||||
|
||||
|
||||
|
||||
# Tasks sorted by this
|
||||
def taskSorter(self, task):
|
||||
if task["inner_path"] == "content.json": return 9999 # Content.json always prority
|
||||
|
@ -96,8 +102,9 @@ class WorkerManager:
|
|||
# Ends and remove a worker
|
||||
def removeWorker(self, worker):
|
||||
worker.running = False
|
||||
if worker.key in self.workers: del(self.workers[worker.key])
|
||||
self.log.debug("Removed worker, workers: %s/%s" % (len(self.workers), MAX_WORKERS))
|
||||
if worker.key in self.workers:
|
||||
del(self.workers[worker.key])
|
||||
self.log.debug("Removed worker, workers: %s/%s" % (len(self.workers), MAX_WORKERS))
|
||||
|
||||
|
||||
# Create new task and return asyncresult
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue