Hi, to prove your point, I replaced

    time.sleep(10)

with 

    t0 = time.time()
    while time.time() - t0 < 5:
        pass

to keep it busy for 5 seconds and not sleep.
But threading.active_count() is still giving me one thread ...

But, as you suggested, str(threading.current_thread()) tells us that they 
are running of different threads.
Is this a bug with .active_count()?

On Tuesday, August 20, 2013 12:46:12 PM UTC+1, Arndt Droullier wrote:
>
> I don't think a sleeping thread counts as active.
>
> Try:
>
> def view(request):
>     print '[%s] \t #Threads: %s' % (
>         id(request), 
>         str(threading.current_thread()))
>
>
> 2013/8/20 socheon <[email protected] <javascript:>>
>
>> Thanks. Yes, the unexpected behaviour was due to my browser (google 
>> chrome or firefox), but I am fine with that.
>>
>> I tried the following code as well, basically printing out the number of 
>> threads in each view.
>> Again, unexpectedly, the count is always 1.
>>
>> Server
>> ======
>>
>> from pyramid.config import Configurator
>> from pyramid.response import Response
>> import time
>> import threading
>>
>> def view(request):
>>     print '[%s] \t #Threads: %s' % (
>>         id(request), 
>>         threading.active_count())
>>     
>>     time.sleep(10)
>>     return Response('Ok')
>>
>> def make_app():
>>     config = Configurator()
>>     config.add_route('view', '/view')
>>     config.add_view(view, route_name='view')
>>     return config.make_wsgi_app()
>>
>> if __name__ == '__main__':
>>     from waitress import serve
>>     serve(make_app(), host='0.0.0.0', port=6543)
>>
>> Client
>> ======
>>
>> On a python interpreter,  
>>     
>>     [subprocess.Popen(['curl', 'localhost:6543/view']) for i in range(10)]
>>
>> Output
>> ======
>>
>> [23590128]       #Threads: 1
>> [23591216]       #Threads: 1
>> [23592080]       #Threads: 1
>> [23671152]       #Threads: 1
>> [23590384]       #Threads: 1
>> [23591376]       #Threads: 1
>> [23592240]       #Threads: 1
>> [23671248]       #Threads: 1
>> [23671632]       #Threads: 1
>> [23672048]       #Threads: 1
>>
>> On Monday, August 19, 2013 9:04:11 PM UTC+1, Jonathan Vanasco wrote:
>>>
>>> That's most likely an issue with your browser 
>>>
>>> This:
>>>
>>> 1- edit view_1 as such:
>>>
>>> def view1(request):
>>>     print 'Start view1 - %s' % id(request)
>>>     time.sleep(10)
>>>     print 'End view1 - %s' % id(request)
>>>     return Response('Ok')
>>>
>>>
>>>
>>> 2- instead of a browser, two terminal windows that each request:
>>>
>>>    curl -O http://0.0.0.0:6543/view1
>>>
>>> you should see something like :
>>>
>>>     Start view1 - 4328272208
>>>     Start view1 - 4328272848
>>>     End view1 - 4328272208
>>>     End view1 - 4328272848
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pylons-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/pylons-discuss.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
>
> ----------------------------------------------------------------------------------------------
> Arndt Droullier, Nive GmbH, Köln, Germany
> Nive Web Application Publishing: < New Prototype > www.nive.co
> Nive Open Source Cms: cms.nive.co
>  

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to