~exarkun/divmod.org/remove-axiom-1325288

« back to all changes in this revision

Viewing changes to Epsilon/epsilon/react.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- test-case-name: epsilon.test.test_react -*-
2
 
# Copyright (c) 2008 Divmod.  See LICENSE for details.
3
 
 
4
 
"""
5
 
Utilities for running the reactor for a while.
6
 
"""
7
 
 
8
 
from twisted.python.log import err
9
 
 
10
 
 
11
 
def react(reactor, main, argv):
12
 
    """
13
 
    Call C{main} and run the reactor until the L{Deferred} it returns fires.
14
 
 
15
 
    @param reactor: An unstarted L{IReactorCore} provider which will be run and
16
 
        later stopped.
17
 
 
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}.
20
 
 
21
 
    @param argv: A list of arguments to pass to C{main}.
22
 
 
23
 
    @return: C{None}
24
 
    """
25
 
    stopping = []
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):
30
 
        if not stopping:
31
 
            reactor.callWhenRunning(reactor.stop)
32
 
    finished.addCallback(cbFinish)
33
 
    reactor.run()
34
 
 
35