Spawing a thread and printing dots until it finishes

Diez B. Roggisch deets at nospam.web.de
Tue Apr 22 15:17:18 EDT 2008


> I think that there are two things that you need to wrap your head
> around before understanding what is happening here.  First, threads are
> NOT pre-emptive.  Unless your thread gives up the processor it will run
> forever.  The sleep call is one way to give up the processor.

That is not correct, at least not on usual OSes. The posix-threads as 
well as windows threads *are* preemptive.

> Second, sleep() does not return as soon as the time given has expired.
> The argument is the MINIMUM amount of time that it waits.  After that
> the thread that slept is put back onto the run queue and is now a
> candidate to be given the processor.  Your other thread still has to
> give up the processor before it can run again and even then there may
> be other threads on the queue ahead of yours.
> 
> So, does your thread ever give up the processor other than by dying?

It shouldn't need to. It will be rescheduled.

The code looks ok to me - the problem seems to be in the R-Python as 
Gabriel pointed out.

Diez



More information about the Python-list mailing list