Hi,<br><br> actually i have simplified my scenario a lot here ,<br><br>In my actual case , i have to call a C-api which blocks on  c select , in a separate thread.<br><br>my thread is getting struck in that api , and thus blocking all the other threads.<br>
Can you point to something which will help me call this blocking C-api call without my thread getting struck.<br><br><br>Thanks<br>Mahesh<br><br><div class="gmail_quote">On Mon, Mar 8, 2010 at 6:03 PM, Steve Holden <span dir="ltr"><<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">Mahesh wrote:<br>
> Hi,<br>
><br>
>  I am having a problem while using sleep function from libc , the<br>
> thread in which i am calling it is getting struck and not allowing<br>
> other threads to execute.  Here is a simple code that i am trying to<br>
> exeute<br>
><br>
> import threading<br>
> import time<br>
> import dl<br>
><br>
><br>
> def dummy1():<br>
>     a=dl.open('/lib/libc.so.6')<br>
>     print "in thread 1 Start"<br>
>     a.call('sleep',2)<br>
>     #time.sleep(2)<br>
>     print "in thread 1 End"<br>
><br>
> def dummy2():<br>
>     print "in thread 2 Start"<br>
>     time.sleep(1)<br>
>     print "in thread 2 End"<br>
> newThread1=threading.Thread(None,dummy1)<br>
> newThread2=threading.Thread(None,dummy2)<br>
> newThread1.start()<br>
> newThread2.start()<br>
><br>
> print "in main"<br>
><br>
><br>
><br>
> The out put of this program is  (In this case thread 1 even though i<br>
> am calling a sleep function its not allowing other threads to execute,<br>
> other threads execute only after the completion of first thread)<br>
><br>
> in thread 1 Start<br>
> in thread 1 End<br>
> in thread 2 Start<br>
> in main<br>
> in thread 2 End<br>
><br>
><br>
> where as if i use time.sleep instead of a.call(sleep) the out put is<br>
> (which i guess is right behaviour, because it start the threads and<br>
> suspends them because the have sleep , and continue executing the main<br>
> thread)<br>
> in thread 1 Start<br>
> in thread 2 Start<br>
> in main<br>
> in thread 2 End<br>
> in thread 1 End<br>
><br>
><br>
</div></div>Why not just use the time module's sleep function? Unlike the libc code<br>
it releases Python's GIL (global interpreter lock), thus allowing other<br>
threads to run.<br>
<br>
regards<br>
 Steve<br>
--<br>
Steve Holden           +1 571 484 6266   +1 800 494 3119<br>
PyCon is coming! Atlanta, Feb 2010  <a href="http://us.pycon.org/" target="_blank">http://us.pycon.org/</a><br>
Holden Web LLC                 <a href="http://www.holdenweb.com/" target="_blank">http://www.holdenweb.com/</a><br>
UPCOMING EVENTS:        <a href="http://holdenweb.eventbrite.com/" target="_blank">http://holdenweb.eventbrite.com/</a><br>
<font color="#888888"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>