0

I want to know what happens the exceptions are not caught inside a greenlet spawn in a gevent.pool. Does it not update the semaphore and make it available so that a new greenlet could be spawn?

I just want to make sure that if the pool has the size of 10 and we have spawn 10 greenlets and all of them throw an uncaught exception, no new greenlets can be spawn. Because they didn't release/terminate in a a normal fashion and the semaphore count is not update.

from gevent import pool

def test(index):
    print(index)
    raise

p = pool.Pool(size=5)

for i in range(10):
    p.spawn(test, i)

p.join()
rajan sthapit
  • 4,194
  • 10
  • 42
  • 66

1 Answers1

0

Here's an example

from gevent.pool import Pool


def work():
  raise Exception("Vzboom!")

pool = Pool(2)

greenlet = pool.spawn(work)
greenlet.run()
print(greenlet.exception)  # => Exception: Vzboom!

It doesn't block and you can always examine if there's an exception as seen (similar to threading.ThreadPoolExecutor with futures).

The big difference is that the exception will show here directly on screen while Python's shipping threadpool will just swallow them (which is annoying to say the least).

Pithikos
  • 18,827
  • 15
  • 113
  • 136