Skip to content

Instantly share code, notes, and snippets.

@erikfrey
Created March 11, 2011 02:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikfrey/865355 to your computer and use it in GitHub Desktop.
Save erikfrey/865355 to your computer and use it in GitHub Desktop.
Threadpool crashes gevent
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()
@denik
Copy link

denik commented Jan 9, 2012

There's a built-in thread pool in gevent now: https://bitbucket.org/denis/gevent/src/5a431f359ca5/gevent/threadpool.py

You can try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment