Search code examples
twisted

Adjust Thread pool size when using twistd


I am going to deploy my app in the twistd way(Application,Service, etc).

I'm wondering if there is a way to adjust the thread pool size of twisted like using reactor.suggestPoolSize()

I found an API called "adjustPoolsize" in twisted.python.threadpool.ThreadPool

Can I call it directly for my purpose?

Thank you!


Solution

  • Recent versions of Twisted let you access the reactor's thread pool:

    from twisted.internet import reactor
    threadpool = reactor.getThreadPool()
    threadpool.adjustPoolsize(3, 7)
    

    However, there's no guarantee that the reactor itself won't re-adjust the size as it sees fit. If you need to control the size of the threadpool used by your application, it may be better to create your own ThreadPool instance, rather than using the reactor's.