<commit_before>import os
from diesel import Loop, fork, Application, clock, sleep

def usage():
    u = os.times()
    return u[0] + u[1]

def not_always_busy_worker(clocker):
    start = clocker()

    for _ in xrange(12):
        use = usage()
        for i in xrange(10000000): # do some work to forward cpu seconds
            pass
        sleep(0.1) # give up control

    end = clocker()
    print "start ", start, " end ", end, " diff ", end - start

def spawn_busy_workers():
    for _ in xrange(0,3):
        fork(not_always_busy_worker, clock)

a = Application()
a.add_loop(Loop(spawn_busy_workers), track=True)
a.run()<commit_msg>show how to use the cpu stats tracking context manager<commit_after>import os
from diesel import Loop, fork, Application, sleep
from diesel.util.stats import CPUStats

def not_always_busy_worker():
    with CPUStats() as stats:
        for _ in xrange(12):
            for i in xrange(10000000): # do some work to forward cpu seconds
                pass
            sleep(0.1) # give up control

    print "cpu seconds ",  stats.cpu_seconds

def spawn_busy_workers():
    for _ in xrange(0,3):
        fork(not_always_busy_worker)

a = Application()
a.add_loop(Loop(spawn_busy_workers), track=True)
a.run()
{'fraction_non_alphanumeric': 0.10256410256410256, 'fraction_numerical': 0.02403846153846154, 'mean_word_length': 3.042071197411003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4397291', 'n_tokens_mistral': 424, 'n_tokens_neox': 400, 'n_words': 125}