开发者

twisted.web2 and spawining threads for synchronous code?

开发者 https://www.devze.com 2022-12-20 08:19 出处:网络
So, I\'m writing a python web application using the twisted web开发者_Go百科2 framework. There\'s a library that I need to use (SQLAlchemy, to be specific) that doesn\'t have asynchronous code. Would

So, I'm writing a python web application using the twisted web开发者_Go百科2 framework. There's a library that I need to use (SQLAlchemy, to be specific) that doesn't have asynchronous code. Would it be bad to spawn a thread to handle the request, fetch any data from the DB, and then return a response? I'm afraid that if there was a flood of requests, too many threads would be started and the server would be overwhelmed. Is there something built into twisted that prevents this from happening (eg request throttling)?


See the docs, and specifically the thread pool which lets you control how many threads are active at most. Spawning one new thread per request would definitely be an inferior idea!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号