root/trunk/twisted/internet/main.py

Revision 29905, 1.0 KB (checked in by screwtape, 4 weeks ago)

Merge let-tests-run-under-python-O-4476: installReactor() does not use assert.

Authors: ivank, screwtape
Reviewers: screwtape, exarkun
Fixes: #4476

twisted.internet.main.installReactor() used to "assert" that no previous
reactor was installed, but "assert" statements are compiled out when
Python runs with the "-O" parameter, which enabled Twisted's test suite
to try installing multiple reactors with no happy result.

Now installReactor() uses an ordinary "if" statement instead of
"assert", and Trial no longer crashes when running the Twisted test
suite in "python -O" mode.

Line 
1# -*- test-case-name: twisted.internet.test.test_main -*-
2# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
3# See LICENSE for details.
4
5
6"""
7Backwards compatibility, and utility functions.
8
9In general, this module should not be used, other than by reactor authors
10who need to use the 'installReactor' method.
11
12Maintainer: Itamar Shtull-Trauring
13"""
14
15import error
16
17CONNECTION_DONE = error.ConnectionDone('Connection done')
18CONNECTION_LOST = error.ConnectionLost('Connection lost')
19
20def installReactor(reactor):
21    """
22    Install reactor C{reactor}.
23
24    @param reactor: An object that provides one or more IReactor* interfaces.
25    """
26    # this stuff should be common to all reactors.
27    import twisted.internet
28    import sys
29    if 'twisted.internet.reactor' in sys.modules:
30        raise error.ReactorAlreadyInstalledError("reactor already installed")
31    twisted.internet.reactor = reactor
32    sys.modules['twisted.internet.reactor'] = reactor
33
34
35__all__ = ["CONNECTION_LOST", "CONNECTION_DONE",
36           "ReactorAlreadyInstalledError", "installReactor"]
Note: See TracBrowser for help on using the browser.