Files
deb-python-eventlet/tests/isolated/patcher_socketserver_selectors.py
Jakub Stasiak 801e7dd65c Fix HTTPServer.serve_forever blocking whole process
Original report: https://github.com/eventlet/eventlet/issues/249

Explanation is in the comments in the code.
2015-11-22 23:12:48 +01:00

29 lines
1.0 KiB
Python

if __name__ == '__main__':
import eventlet
eventlet.monkey_patch()
from eventlet.support.six.moves.BaseHTTPServer import (
HTTPServer,
BaseHTTPRequestHandler,
)
import threading
server = HTTPServer(('localhost', 0), BaseHTTPRequestHandler)
thread = threading.Thread(target=server.serve_forever)
# Before fixing it the code would never go pass this line because:
# * socketserver.BaseServer that's used behind the scenes here uses
# selectors.PollSelector if it's available and we don't have green poll
# implementation so this just couldn't work
# * making socketserver use selectors.SelectSelector wasn't enough as
# until now we just failed to monkey patch selectors module
#
# Due to the issues above this thread.start() call effectively behaved
# like calling server.serve_forever() directly in the current thread
#
# Original report: https://github.com/eventlet/eventlet/issues/249
thread.start()
server.shutdown()
print('pass')