THREADS use 100 % CPU all the time

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 11 14:35:26 EDT 2007


En Wed, 11 Apr 2007 08:36:57 -0300, A.B., Khalid <khabkr at yahoo.com>  
escribió:

> On Apr 11, 2:38 am, matthiasja... at gmx.net wrote:

>> I have a application where I use different threads. actually all is
>> working - BUT I just discovered that the [b]CPU is always 100 % [/
>> b]used.
>>
> You need your program to sleep a while to allow a switch to other
> tasks. Like so:
>
> t = TestThread()
> t.start()
>
> while (True):
>     time.sleep(0.01)
>     pass

If all you want is to wait until the thread finishes, use t.join() instead  
of that infinite loop.

-- 
Gabriel Genellina



More information about the Python-list mailing list