does gevent create thread automatically?

178 views
Skip to first unread message

Fei Li

unread,
Jan 16, 2015, 12:44:06 PM1/16/15
to gev...@googlegroups.com
I use gevent in single thread under uWSGI. The code is below.

def fetch_dataA():
    return gevent_clientA.fetch()

def fetch_dataB():
    return gevent_clientB.fetch()

def fetch_dataC():
    return gevent_clientC.fetch()

def views(request):

gs = []
for f in (fetch_dataA, fetch_dataB, fetch_dataC):
   g = gevent.spawn(f)
   gs.append(g)

gevent.join_all(gs, timeout=2.5)

for g in gs:
g.get()

return


I found uWSGI Python tracebacker output show a threadpool with 3 work threads was created. I don't think gevent create thread. I thought all greenlet will run under one single thread. So Does anybody tell me what's going on here?


uWSGI Python tracebacker output 

thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/threadpool.p
y lineno = 182 function = _worker line = task = task_queue.get()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.p
y lineno = 432 function = get line = self.not_empty.wait()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.p
y lineno = 148 function = wait line = waiter.acquire()

thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/threadpool.p
y lineno = 182 function = _worker line = task = task_queue.get()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.p
y lineno = 432 function = get line = self.not_empty.wait()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.p
y lineno = 148 function = wait line = waiter.acquire()

thread_id = MainThread filename = /usr/lib/python2.7/site-packages/gevent/hub.py lineno = 364 fun
ction = run line = loop.run()

thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/threadpool.p
y lineno = 182 function = _worker line = task = task_queue.get()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.p
y lineno = 432 function = get line = self.not_empty.wait()
thread_id = <UnnamedPythonThread> filename = /usr/lib/python2.7/site-packages/gevent/_threading.py lineno = 148 function = wait line = waiter.acquire()

 backtrace of 14706

Fantix King

unread,
Jan 18, 2015, 5:26:56 AM1/18/15
to gev...@googlegroups.com
It's probably that your gevent didn't build with c-ares correctly, which led gevent to use thread pool for name resolving.

--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fei Li

unread,
Jan 18, 2015, 6:04:10 AM1/18/15
to gev...@googlegroups.com
thank you.

Fantix King

unread,
Jan 18, 2015, 6:09:42 AM1/18/15
to gev...@googlegroups.com
不客气
Reply all
Reply to author
Forward
0 new messages