Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow for providing our own ioloop #4

Merged
merged 1 commit into from

2 participants

@rhettg

Using the global default ioloop doesn't alway work. This just adds optional arguments.

@danielhfrank

sorry 4 the wait

@danielhfrank danielhfrank merged commit ccbe547 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 6, 2012
  1. @rhettg
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 7 deletions.
  1. +3 −3 asyncdynamo/async_aws_sts.py
  2. +5 −4 asyncdynamo/asyncdynamo.py
View
6 asyncdynamo/async_aws_sts.py
@@ -48,13 +48,13 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None, path='/',
- converter=None):
+ converter=None, ioloop=None):
STSConnection.__init__(self, aws_access_key_id,
aws_secret_access_key,
is_secure, port, proxy, proxy_port,
proxy_user, proxy_pass, debug,
https_connection_factory, region, path, converter)
- self.http_client = AsyncHTTPClient()
+ self.http_client = AsyncHTTPClient(io_loop=ioloop)
def get_session_token(self, callback):
'''
@@ -112,4 +112,4 @@ def make_request(self, action, params={}, path='/', verb='GET', callback=None):
def _finish_make_request(self, response, callback):
if response.error:
return callback(response.body, error=response.error)
- return callback(response.body)
+ return callback(response.body)
View
9 asyncdynamo/asyncdynamo.py
@@ -77,7 +77,7 @@ class AsyncDynamoDB(AWSAuthConnection):
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
host=None, debug=0, session_token=None,
- authenticate_requests=True, validate_cert=True, max_sts_attempts=3):
+ authenticate_requests=True, validate_cert=True, max_sts_attempts=3, ioloop=None):
if not host:
host = self.DefaultHost
self.validate_cert = validate_cert
@@ -87,9 +87,10 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
aws_secret_access_key,
is_secure, port, proxy, proxy_port,
debug=debug, security_token=session_token)
- self.http_client = AsyncHTTPClient()
+ self.ioloop = ioloop or IOLoop.instance()
+ self.http_client = AsyncHTTPClient(io_loop=self.ioloop)
self.pending_requests = deque()
- self.sts = AsyncAwsSts(aws_access_key_id, aws_secret_access_key)
+ self.sts = AsyncAwsSts(aws_access_key_id, aws_secret_access_key, ioloop=self.ioloop)
assert (isinstance(max_sts_attempts, int) and max_sts_attempts >= 0)
self.max_sts_attempts = max_sts_attempts
@@ -141,7 +142,7 @@ def raise_error():
else:
seconds_to_wait = (0.1*(2**attempts))
logging.warning("Got error[ %s ] getting session token, retrying in %.02f seconds" % (error, seconds_to_wait))
- IOLoop.instance().add_timeout(time.time() + seconds_to_wait,
+ self.ioloop.add_timeout(time.time() + seconds_to_wait,
functools.partial(self._update_session_token, attempts=attempts+1, callback=callback, bypass_lock=True))
return
else:
Something went wrong with that request. Please try again.