each process only has one main thread ,right ?

Dave Angel d at davea.name
Wed Feb 6 15:59:15 CET 2013


On 02/06/2013 06:52 AM, Steven D'Aprano wrote:
> iMath wrote:
>
>> When a program starts up, one thread begins running immediately. This is
>> usually called the main thread of the program ,so each process only has
>> one main thread ,right ?
>
> I'm not sure if we should say "each process HAS one main thread" or "each
> process IS one main thread", or whether there is in fact a difference. But,
> yes, each process is equivalent to a single thread.
>
>

Each process merely starts out as a single thread.  If it creates other 
threads, they are usually not considered main threads.

OP:  But note that if a process is running under a debugger, or an IDE, 
that debugger may inject one or more threads into the process.

The only place I now of where we care whether a particular thread in a 
process is "the main thread" is with a gui, which usually can only sit 
in a single, "main" thread.  Any gui-related processing done in other 
threads must be done very carefully.

-- 
DaveA



More information about the Python-list mailing list