threads and sleep?

Peter Hansen peter at
Tue Jul 5 00:36:07 CEST 2005

Jeffrey Maitland wrote:
> I am in the process of writing a multithreading program and what I was
> wondering is a sleep command in an executing function will affect the
> threads below it? 

Note that the "executing function" is itself running inside a thread, 
specifically the "main thread".  The other threads are not "below" it in 
any particular sense, more like beside it.  (Or, to put it another way, 
there is no such concept of relative position with threads in Python.)

Here is a basic example of what I mean.
[snip code]
> so the question I was wondering is if the sleep will pause the t
> thread as well as the main function or is the thread independat of the
> main function sleep?

Your code is very close to working already... why don't you just run it 
and observe how it works?

In any case, the answer is "no, time.sleep() affects only the current 


More information about the Python-list mailing list