Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:30:53+00:00 2026-06-17T23:30:53+00:00

I run some task using eventlet.GreenPool.spawn, then wait for all greanthreads to finish. I

  • 0

I run some task using eventlet.GreenPool.spawn, then wait for all greanthreads to finish. I know there would be an exception raised – how can I catch that exception and throw it in a main thread? I am pretty sure it’s easy however I’m totally missing something.

Here is an example (which fails and I would like it to succeed)

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()

and it’s output:

> 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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:30:54+00:00Added an answer on June 17, 2026 at 11:30 pm

    Eventlet’s event loop swallows all exceptions, barring KeyboardInterrupt and SystemExit. Check the wait() implementation of various eventlet hubs. The following excerpt is from select hub’s wait():

    for listeners, events in ((readers, r), (writers, w)):
        for fileno in events:
            try:
                listeners.get(fileno, noop).cb(fileno)
            except self.SYSTEM_EXCEPTIONS:
                raise
            except:
                self.squelch_exception(fileno, sys.exc_info())
                clear_sys_exc_info()
    

    To work around this, you can pass the exception info as value and deal with it later in the main thread.

    import unittest2
    import sys
    import eventlet
    
    
    def broken_fetch(url):
        print " Raising exception "
        try:
            raise RuntimeError
        except:
            return sys.exc_info()
    
    class TestPool(unittest2.TestCase):
    
        def test_error_is_bubbled_up(self):
            with self.assertRaises(RuntimeError):
                pool = eventlet.GreenPool(100)
                urls = ['http://google.com/', 'http://example.com/']
                for exc_info in pool.imap(broken_fetch, urls):
                    if exc_info is not None:
                        exc_class, value, tb = exc_info
                        raise exc_class, value, tb
    
    if __name__ == '__main__':
        unittest2.main()
    

    You may want to turn off eventlet’s DEBUG flag to prevent eventlet from printing the swallowed exception. When you want to handle the exception in main thread, you probably don’t want to get confused by the duplicated traceback print.

    import eventlet.debug
    eventlet.debug.hub_exceptions(False)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run some task using screen there was some error. I want to
i want to run some command on several machine using ssh. I know it
I'm trying to run some tests in Ant presently using JUnit, and all of
I need to run some p4 commands using a filespec with a changelist but
Currently I'm using ruby rake to run ALL selenium ruby webdriver scripts that I
I know there are various ways to limit how long a task runs under
Using GetKeyState, I can do some task when a key is pressed. However, if
I've run into some nasty problem with my recorder. Some people are still using
I want to run some commands via a remote program. I've tried it using
I am using delayed_job to do some background task. In between I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.