@contextmanager<EOL>def loop_in_background(interval, callback):
loop = GeventLoop(interval, callback)<EOL>loop.start()<EOL>try:<EOL><INDENT>yield loop<EOL><DEDENT>finally:<EOL><INDENT>if loop.has_started():<EOL><INDENT>loop.stop()<EOL><DEDENT><DEDENT>
When entering the context, spawns a greenlet that sleeps for `interval` seconds between `callback` executions.
When leaving the context stops the greenlet.
The yielded object is the `GeventLoop` object so the loop can be stopped from within the context.

For example:
```
with loop_in_background(60.0, purge_cache) as purge_cache_job:
    ...
    ...
    if should_stop_cache():
        purge_cache_job.stop()
```