Reputation: 42110
I am coming from Java background and absolutely new at Python.
I need to write a simple web server to handle multiple concurrent requests. The request processing is mostly CPU bound and handling a single request may take 100 - 1000 ms. The server will run on a multicore machine.
I was advised to use Tornado
with a thread pool. Do you have any example ?
Upvotes: 2
Views: 1414
Reputation: 24027
If the processing of a single request is mostly CPU-bound, a thread pool won't help. Python's Global Interpreter Lock (GIL) prevents more than one thread from running Python in any one Python process. Instead, start a Tornado process per core.
Follow this example from the Tornado docs:
server = HTTPServer(app)
server.bind(8888)
server.start(0) # Forks multiple sub-processes
IOLoop.current().start()
Upvotes: 4