eventlet.GreenPool.spawnを使用していくつかのタスクを実行し、すべてのgreanthreadsが終了するのを待ちます。例外が発生することはわかっています-その例外をキャッチしてメインスレッドにスローするにはどうすればよいですか?簡単だと思いますが、何かが足りません。
これが例です(失敗し、成功したいです)
import unittest
import eventlet
def broken_fetch(url):
print " Raising exception "
raise RuntimeError
class TestPool(unittest.TestCase):
def test_error_is_bubbled_up(self):
with self.assertRaises(RuntimeError):
pool = eventlet.GreenPool(100)
urls = ['http://google.com/', 'http://example.com/']
for url in urls:
pool.spawn(broken_fetch, url)
pool.waitall()
if __name__ == '__main__':
unittest.main()
そしてそれは出力です:
> python errors.py
Raising exception
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/eventlet/hubs/hub.py", line 336, in fire_timers
timer()
File "/usr/local/lib/python2.7/site-packages/eventlet/hubs/timer.py", line 56, in __call__
cb(*args, **kw)
File "/usr/local/lib/python2.7/site-packages/eventlet/greenthread.py", line 192, in main
result = function(*args, **kwargs)
File "errors.py", line 10, in broken_fetch
raise RuntimeError
RuntimeError
Raising exception
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/eventlet/hubs/hub.py", line 336, in fire_timers
timer()
File "/usr/local/lib/python2.7/site-packages/eventlet/hubs/timer.py", line 56, in __call__
cb(*args, **kw)
File "/usr/local/lib/python2.7/site-packages/eventlet/greenthread.py", line 192, in main
result = function(*args, **kwargs)
File "errors.py", line 10, in broken_fetch
raise RuntimeError
RuntimeError
F
======================================================================
FAIL: test_error_is_bubbled_up (__main__.TestPool)
----------------------------------------------------------------------
Traceback (most recent call last):
File "errors.py", line 21, in test_error_is_bubbled_up
pool.waitall()
AssertionError: RuntimeError not raised
----------------------------------------------------------------------
Ran 1 test in 0.003s
FAILED (failures=1)