Skip to content

Commit

Permalink
Support custom executors in AsyncAPI, add AsyncAPI to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bujniewicz committed Oct 23, 2016
1 parent c18cfee commit 9564799
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
22 changes: 19 additions & 3 deletions devourer/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
from devourer import GenericAPICreator


# Default time (seconds) to wait for thread before timing out
# Default time (seconds) to wait for thread before timing out.
DEFAULT_ASYNC_TIMEOUT = 5.0

# Default number of executors for an API instance
# Default executor class.
DEFAULT_EXECUTOR = ThreadPoolExecutor

# Default number of executors for an API instance.
DEFAULT_EXECUTORS = 2


Expand All @@ -30,8 +33,21 @@ class AsyncAPIBase(GenericAPIBase):
_methods = None

def __init__(self, *args, **kwargs):
"""
Add async settings and invoke base initializer.
:param args:
:param executors: number of concurrent executor workers.
:param executor_class: executor class.
:param executor: executor instance. Takes priority over executor_class.
:param kwargs:
"""
executor = kwargs.pop('executor', None)
executors = kwargs.pop('executors', DEFAULT_EXECUTORS)
self._executor = ThreadPoolExecutor(max_workers=executors)
executor_class = kwargs.pop('executor_class', DEFAULT_EXECUTOR)
if executor:
self._executor = executor
else:
self._executor = executor_class(max_workers=executors)
super(AsyncAPIBase, self).__init__(*args, **kwargs)

def call(self, name, *args, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Contents:
.. autoclass:: GenericAPI
:members:

.. autoclass:: AsyncAPI
:members:

.. autoclass:: APIMethod
:members:

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='devourer',
packages=['devourer'],
version='0.4.1',
version='0.4.2',
install_requires=[
'requests',
'futures',
Expand All @@ -14,7 +14,7 @@
author='Bonnier Business Polska / Krzysztof Bujniewicz',
author_email='racech@gmail.com',
url='https://github.com/bonnierpolska/devourer',
download_url='https://github.com/bonnierpolska/devourer/tarball/0.4.1',
download_url='https://github.com/bonnierpolska/devourer/tarball/0.4.2',
keywords=['api', 'generic api', 'api client'],
classifiers=[]
)

0 comments on commit 9564799

Please sign in to comment.