try:
    # for unix systems
    import resource
    def clock():
        """clock() -> floating point number

        Return the CPU time in seconds (user + system) since the start of the
        process.  This is done via a call to resource.getrusage, so it avoids
        the wraparound problems in time.clock()."""

        res = resource.getrusage(resource.RUSAGE_SELF)
        return res[0]+res[1]
except:
    # other systems
    from time import clock

class CPU:
    def __init__(self, max_time):
        self.max_time = max_time
        self.init_time = clock()
    def over(self):
        return clock()-self.init_time > self.max_time
