libc Sleep api performs a busy waiting

Joe Fox fox.joe87 at
Mon Mar 8 10:30:45 CET 2010

Hi ,

 I am having a problem while using sleep function from libc , the
thread in which i am calling it is getting struck and not allowing
other threads to execute.  Here is a simple code that i am trying to

import threading
import time
import dl

def dummy1():'/lib/')
    print "in thread 1 Start"'sleep',2)
    print "in thread 1 End"

def dummy2():
    print "in thread 2 Start"
    print "in thread 2 End"

print "in main"

The out put of this program is  (In this case thread 1 even though i
am calling a sleep function its not allowing other threads to execute,
other threads execute only after the completion of first thread)

in thread 1 Start
in thread 1 End
in thread 2 Start
in main
in thread 2 End
where as if i use time.sleep instead of the out put is
(which i guess is right behaviour, because it start the threads and
suspends them because the have sleep , and continue executing the main
in thread 1 Start
in thread 2 Start
in main
in thread 2 End
in thread 1 End

Can any of you point me how to over come this.?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list