1
# -*- test-case-name: epsilon.test.test_react -*-
2
# Copyright (c) 2008 Divmod. See LICENSE for details.
5
Utilities for running the reactor for a while.
8
from twisted.python.log import err
11
def react(reactor, main, argv):
13
Call C{main} and run the reactor until the L{Deferred} it returns fires.
15
@param reactor: An unstarted L{IReactorCore} provider which will be run and
18
@param main: A callable which returns a L{Deferred}. It should take as
19
many arguments as there are elements in the list C{argv}.
21
@param argv: A list of arguments to pass to C{main}.
26
reactor.addSystemEventTrigger('before', 'shutdown', stopping.append, True)
27
finished = main(reactor, *argv)
28
finished.addErrback(err, "main function encountered error")
29
def cbFinish(ignored):
31
reactor.callWhenRunning(reactor.stop)
32
finished.addCallback(cbFinish)