Doubt on creating threads
exarkun at divmod.com
Sat Jan 3 18:41:35 CET 2009
On Sat, 3 Jan 2009 08:39:52 -0800 (PST), koranthala at gmail.com wrote:
>I was going through Python posts and this post caught my attention
> You have missed an important point. A well designed application does
> neither create so many threads nor processes. The creation of a
> or forking of a process is an expensive operation. You should use a
> of threads or processes.
>I am creating an application and it creates ~1-2 threads every second
>and kill it within 10 seconds. After reading this I am worried. Is
>creating a thread a very costly operation? I cannot use a pool of
>threads because I am using an external application (twisted) to create
>the threads (deferToThread).
Actually, deferToThread is implemented in terms of a thread pool. So
you're only creating a small number of threads, and then they're being
I somewhat disagree with the assertion that not using a threadpool means
that your application is "well designed". However, it's absolutely true
that using a threadpool lowers the runtime cost of using threads compared
to creating and destroying threads all the time.
More information about the Python-list