Created
March 11, 2011 02:20
-
-
Save erikfrey/865355 to your computer and use it in GitHub Desktop.
Threadpool crashes gevent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threadpool import ThreadPool | |
import random | |
import gevent | |
import gevent.pool | |
iterations = 1000000 | |
max_stack_depth = 50 | |
def source(tp): | |
for i in xrange(0, iterations): | |
i = tp.apply(threaded, i) | |
if i % 10000 == 0: | |
print i | |
def recurse(x, y, z, remaining): | |
if remaining: | |
return recurse(x, y, z, remaining - 1) | |
return 0 | |
def threaded(i): | |
recurse(1, 2, 3, random.randint(0, max_stack_depth)) | |
return i | |
tp = ThreadPool(poolsize=100) | |
p1 = gevent.pool.Pool(size=1) | |
p1.spawn(source, tp) | |
p1.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a built-in thread pool in gevent now: https://bitbucket.org/denis/gevent/src/5a431f359ca5/gevent/threadpool.py
You can try that.