#!/usr/bin/env python
# Tai Sakuma <tai.sakuma@cern.ch>
from AlphaTwirl.ProgressBar import ProgressBar, MPProgressMonitor, ProgressReport
from AlphaTwirl.Concurrently import CommunicationChannel
import time, random
import uuid

##____________________________________________________________________________||
class Task(object):
    def __init__(self, name):
        self.name = name
    def __call__(self, progressReporter = None):
        n = random.randint(5, 1000000)
        taskid = uuid.uuid4()
        time.sleep(random.randint(0, 3))
        for i in xrange(n):
            time.sleep(0.0001)
            report = ProgressReport(name = self.name, done = i + 1, total = n, taskid = taskid)
            progressReporter.report(report)
        return None

##____________________________________________________________________________||
progressBar = ProgressBar()
progressMonitor = MPProgressMonitor(presentation = progressBar)
channel = CommunicationChannel(nprocesses = 10, progressMonitor = progressMonitor)
channel.begin()
channel.put(Task("loop"))
channel.put(Task("another loop"))
channel.put(Task("more loop"))
channel.put(Task("loop loop loop"))
channel.put(Task("l"))
channel.put(Task("loop6"))
channel.put(Task("loop7"))
channel.put(Task("loop8"))
channel.put(Task("loop6"))
channel.receive()
channel.end()

##____________________________________________________________________________||

@@ -97,26 +97,24 @@
 essBar, 
-MP
 Progress
 Monitor,
@@ -109,25 +109,25 @@
 ress
-Monitor
+Report
 , 
+B
 Progress
 Repo
@@ -122,22 +122,23 @@
 Progress
-Rep
+Monit
 or
-t
 %0Afrom Al
@@ -288,26 +288,16 @@
 ________
-__________
 %7C%7C%0Aclass
@@ -813,26 +813,16 @@
 ________
-__________
 %7C%7C%0Aprogr
@@ -866,10 +866,9 @@
 r = 
-MP
+B
 Prog
@@ -990,16 +990,40 @@
 onitor)%0A
+progressMonitor.begin()%0A
 channel.
@@ -1319,16 +1319,38 @@
 el.end()
+%0AprogressMonitor.end()
 %0A%0A##____

update examples/progressbar.py