Add tpool.killall function which can be used to cleanly exit the threadpool.
This commit is contained in:
@@ -61,7 +61,10 @@ def esend(meth,*args, **kwargs):
|
|||||||
def tworker():
|
def tworker():
|
||||||
global _reqq, _rspq
|
global _reqq, _rspq
|
||||||
while(True):
|
while(True):
|
||||||
(e,meth,args,kwargs) = _reqq.get()
|
msg = _reqq.get()
|
||||||
|
if msg is None:
|
||||||
|
return
|
||||||
|
(e,meth,args,kwargs) = msg
|
||||||
rv = None
|
rv = None
|
||||||
try:
|
try:
|
||||||
rv = meth(*args,**kwargs)
|
rv = meth(*args,**kwargs)
|
||||||
@@ -96,6 +99,7 @@ def execute(meth,*args, **kwargs):
|
|||||||
erpc = execute
|
erpc = execute
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Proxy(object):
|
class Proxy(object):
|
||||||
""" a simple proxy-wrapper of any object that comes with a methods-only interface,
|
""" a simple proxy-wrapper of any object that comes with a methods-only interface,
|
||||||
in order to forward every method invocation onto a thread in the native-thread pool.
|
in order to forward every method invocation onto a thread in the native-thread pool.
|
||||||
@@ -123,6 +127,7 @@ class Proxy(object):
|
|||||||
return rv
|
return rv
|
||||||
return doit
|
return doit
|
||||||
|
|
||||||
|
|
||||||
_nthreads = int(os.environ.get('EVENTLET_THREADPOOL_SIZE', 20))
|
_nthreads = int(os.environ.get('EVENTLET_THREADPOOL_SIZE', 20))
|
||||||
_threads = {}
|
_threads = {}
|
||||||
def setup():
|
def setup():
|
||||||
@@ -135,3 +140,11 @@ def setup():
|
|||||||
api.spawn(tpool_trampoline)
|
api.spawn(tpool_trampoline)
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
|
|
||||||
|
def killall():
|
||||||
|
for i in _threads:
|
||||||
|
_reqq.put(None)
|
||||||
|
for thr in _threads.values():
|
||||||
|
thr.join()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user