Callback for long metric calculations.

3 views
Skip to first unread message

Chris

unread,
Dec 3, 2008, 12:56:13 PM12/3/08
to networkx-discuss
I think it would be a great thing for complex metric calculations if a
callback was used to update a percentage complete while the metric was
being calculated. In this case, we would be able to open a thread to
calculate the metric and allow the callback to update an interface.

Aric Hagberg

unread,
Dec 3, 2008, 3:21:52 PM12/3/08
to networkx...@googlegroups.com

I agree it is useful to have a progress meter. I've used
some lightly modified networkx code with the progressbar package.
http://pypi.python.org/pypi/progressbar/2.2

I'm not clear on how to implement something in a clean way.
Do you have some suggestions?

Aric

Chris

unread,
Dec 3, 2008, 3:56:57 PM12/3/08
to networkx-discuss

Well, we would have to customize each function/method call to
calculate its own percentage complete as it progressed. In this case
we could add a method parameter called 'callback' and the agreement is
that the function you pass as the parameter would be called
periodically with a value.

implementation example:
In your class:
def myfunc(status):
statusbar.pct = status # or whatever does your UI update

calculate_metric([params], callback=self.myfunc)

In networkx:
def calculate_metric([the usual params], callback=None):
# do some stuff ...
if callback:
callback(0.5)
# do more stuff ...
if callback:
callback(1)

Percentage complete estimates should not be too difficult when we know
things like the number of edges that will be calculated and the number
that have already been calculated for a given metric...
Reply all
Reply to author
Forward
0 new messages