Created
February 1, 2013 21:47
-
-
Save FooBarWidget/4694390 to your computer and use it in GitHub Desktop.
Run ./errortest.py, then run another ./errortest.py while the first one is still running. The second one *should* exit with an error, but instead it gets stuck in the event loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
# This is just for me. Comment this out if you want. | |
sys.path.insert(0, 'Twisted-12.2.0') | |
sys.path.insert(0, 'zope.interface-4.0.1') | |
import logging | |
from twisted.internet import reactor, protocol | |
from twisted.internet.endpoints import TCP4ServerEndpoint | |
def errorHandler(failure): | |
logger = logging.getLogger('tunnel_server') | |
logger.error("CRITICAL ERROR IN SERVER: %s" % failure.getErrorMessage()) | |
logger.error(failure.getTraceback(0, 'verbose')) | |
print '!!!!!!!!!! Stopping server!' | |
sys.exit(1) | |
class Kernel(protocol.Factory): | |
pass | |
if __name__ == "__main__": | |
logger = logging.getLogger('tunnel_server') | |
hdlr = logging.StreamHandler(sys.stdout) | |
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
hdlr.setFormatter(formatter) | |
logger.addHandler(hdlr) | |
logger.setLevel(logging.DEBUG) | |
endpoint = TCP4ServerEndpoint(reactor, 1234) | |
listener = endpoint.listen(Kernel()) | |
listener.addErrback(errorHandler) | |
logger.info("All ready, entering reactor main loop") | |
reactor.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Running errortest.py while another instance is already running | |
$ python errortest.py | |
2013-02-01 22:47:16,046 ERROR CRITICAL ERROR IN SERVER: Couldn't listen on any:1234: [Errno 48] Address already in use. | |
2013-02-01 22:47:16,046 ERROR *--- Failure #6 (pickled) --- | |
errortest.py:31: <module>(...) | |
Twisted-12.2.0/twisted/internet/endpoints.py:271: listen(...) | |
[Capture of Locals and Globals disabled (use captureVars=True)] | |
--- <exception caught here> --- | |
Twisted-12.2.0/twisted/internet/defer.py:105: execute(...) | |
Twisted-12.2.0/twisted/internet/posixbase.py:476: listenTCP(...) | |
Twisted-12.2.0/twisted/internet/tcp.py:969: startListening(...) | |
[Capture of Locals and Globals disabled (use captureVars=True)] | |
twisted.internet.error.CannotListenError: Couldn't listen on any:1234: [Errno 48] Address already in use. | |
*--- End of Failure #6 --- | |
!!!!!!!!!! Stopping server! | |
2013-02-01 22:47:16,046 INFO All ready, entering reactor main loop | |
(at this point, the process is stuck here even though it should exit with exit code 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment