Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix threadpool testing errors #32

Merged
merged 2 commits into from
Aug 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kingpin/actors/aws/test/test_elb.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_is_healthy(self):
mock.Mock(state='InService'),
mock.Mock(state='OutOfService'),
mock.Mock(state='OutOfService'),
]
]
val = yield actor._is_healthy(elb, 3)

self.assertTrue(val)
37 changes: 21 additions & 16 deletions kingpin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
# Constants for some of the utilities below
STATIC_PATH_NAME = 'static'

# Allow up to 10 threads to be executed at once. This is arbitrary, but we
# want to prvent the app from going thread-crazy.
THREADPOOL_SIZE = 10
THREADPOOL = futures.ThreadPoolExecutor(THREADPOOL_SIZE)
# Disable the global threadpool defined here to try to narrow down the random
# unit test failures regarding the IOError. Instead, instantiating a new
# threadpool object for every thread using the 'with' context below.
#
# # Allow up to 10 threads to be executed at once. This is arbitrary, but we
# # want to prvent the app from going thread-crazy.
# THREADPOOL_SIZE = 10
# THREADPOOL = futures.ThreadPoolExecutor(THREADPOOL_SIZE)


def str_to_class(string):
Expand Down Expand Up @@ -144,18 +148,19 @@ def thread_coroutine(func, *args, **kwargs):
Args:
func: Function reference
"""
try:
ret = yield THREADPOOL.submit(func, *args, **kwargs)
except requests.exceptions.ConnectionError as e:
# The requests library can fail to fetch sometimes and its almost
# always OK to re-try the fetch at least once. If the fetch fails a
# second time, we allow it to be raised.
#
# This should be patched in the python-rightscale library so it
# auto-retries, but until then we have a patch here to at least allow
# one automatic retry.
log.debug('Fetch failed. Will retry one time: %s' % e)
ret = yield THREADPOOL.submit(func, *args, **kwargs)
with futures.ThreadPoolExecutor(1) as tp:
try:
ret = yield tp.submit(func, *args, **kwargs)
except requests.exceptions.ConnectionError as e:
# The requests library can fail to fetch sometimes and its almost
# always OK to re-try the fetch at least once. If the fetch fails a
# second time, we allow it to be raised.
#
# This should be patched in the python-rightscale library so it
# auto-retries, but until then we have a patch here to at least
# allow one automatic retry.
log.debug('Fetch failed. Will retry one time: %s' % e)
ret = yield tp.submit(func, *args, **kwargs)

raise gen.Return(ret)

Expand Down