|
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 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | """ |
|---|
| 7 | Backwards compatibility, and utility functions. |
|---|
| 8 | |
|---|
| 9 | In general, this module should not be used, other than by reactor authors |
|---|
| 10 | who need to use the 'installReactor' method. |
|---|
| 11 | |
|---|
| 12 | Maintainer: Itamar Shtull-Trauring |
|---|
| 13 | """ |
|---|
| 14 | |
|---|
| 15 | import error |
|---|
| 16 | |
|---|
| 17 | CONNECTION_DONE = error.ConnectionDone('Connection done') |
|---|
| 18 | CONNECTION_LOST = error.ConnectionLost('Connection lost') |
|---|
| 19 | |
|---|
| 20 | def installReactor(reactor): |
|---|
| 21 | """ |
|---|
| 22 | Install reactor C{reactor}. |
|---|
| 23 | |
|---|
| 24 | @param reactor: An object that provides one or more IReactor* interfaces. |
|---|
| 25 | """ |
|---|
| 26 | |
|---|
| 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"] |
|---|