Exemple #1
0
class ProcessBase(Thread):
    def __init__(self, item_type, lock):
        super(ProcessBase, self).__init__()
        self.queue = WorkerQueue()
        self.start_time = time.time()
        self.added = False
        self.running = False
        self.completed = False
        self.item_type = item_type
        self.lock = lock

    def timer(self):
        if not self.completed:
            self._update_progress()
            Timer(60, self.timer).start()

    def put(self, item):
        self.queue.put(item)

    def _update_progress(self):
        if not self.running:
            return
        done_url = self.queue.get_done()
        total_url = self.queue.get_total()
        total_percentage = done_url * 100.0 / total_url
        print("\n[{0:5.2f}%] {1} remaining {2}s ({3} total {2}s)".format(total_percentage, total_url - done_url,
                                                                         self.item_type, total_url))
Exemple #2
0
class TestWorkerQueue(object):
    def __init__(self):
        self.wq = None

    def setup(self):
        self.wq = WorkerQueue()
        assert self.wq.get_total() == 0
        assert self.wq.get_done() == 0

    def teardown(self):
        del self.wq

    def test_get_total(self):
        self.wq.put('test')
        assert self.wq.get_total() == 1

    def test_get_done(self):
        self.test_get_total()
        self.wq.task_done()
        assert self.wq.get_done() == 1

    def test_reset_count(self):
        self.test_get_done()
        self.wq.reset_count()
        assert self.wq.get_total() == 0
        assert self.wq.get_done() == 0