tags:

views:

65

answers:

2

I want to make Waf generate a beep when it finishes the execution of any command that took more than 10 seconds.

I don't know how do add this and assure that the code executes when Waf exits.

This should run for any Waf command not only build.

I checked the Waf book but I wasn't able to find any indication about how should I do this.

+3  A: 

In your wscript module, you can use the Python standard library's atexit to register callables that you want to be called when the process exit. For example:

import atexit
import time

class MayBeep(object):
  def __init__(self, deadline=10.0):
    self.deadline = time.time() + deadline
  def __call__(self):
    if time.time() > self.deadline():
      print '\7'

atexit.register(MayBeep())

... rest of your wscript module ...

Of course you may use something better than print '\7' for beeping purposes (all the way to full-fledged multimedia extravaganzas, depending on what other Python extensions you import and use), but this code answers the Q's title -- "add code that's always executed on exit".

Alex Martelli
3 beeps can wake anyone!
Sorin Sbarnea
A: 

Did you try out init() and shutdown() in your wscript? They run at Startup, before anything else for init(), and at the end of the wscript after anything else for shutdown(). They both have no args.

none