简体   繁体   中英

How to use Tornado with a thread pool?

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 ?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM