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