Skip to content

Commit ad3fd87

Browse files
authored
Merge pull request #79 from python-effect/py3.7-support
Py3.7 support
2 parents 9946975 + aef6b18 commit ad3fd87

File tree

12 files changed

+70
-56
lines changed

12 files changed

+70
-56
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ python:
66
- "3.4"
77
- "3.5"
88
- "pypy"
9+
matrix:
10+
include:
11+
- python: 3.7
12+
dist: xenial
13+
sudo: true
914
install:
1015
- pip install .
1116
- pip install -r dev-requirements.txt

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ upload-dist:
1616
doc:
1717
rm -rf docs/build
1818
rm -rf docs/source/api
19-
cd docs; sphinx-apidoc -e -o source/api ../effect ../setup.py ../examples ../effect/test_*.py
19+
cd docs; sphinx-apidoc -e -o source/api ../effect ../setup.py ../examples ../effect/test_*.py ../effect/async.py
2020
rm docs/source/api/modules.rst
2121
rm docs/source/api/effect.rst
2222
# can't use sed -i on both linux and mac, so...

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
testtools
22
flake8
33
pytest
4+
sphinx
5+
sphinx-rtd-theme

docs/source/api/effect.async.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
effect.parallel\_async module
2+
=============================
3+
4+
.. automodule:: effect.parallel_async
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

effect/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def perform(dispatcher, effect):
116116
117117
.. [#dispatcher] The dispatcher is passed because some performers need to
118118
make recursive calls to :func:`perform`, because they need to perform
119-
other effects (see :func:`parallel` and :func:`.perform_parallel_async`
120-
for an example of this).
119+
other effects (see :func:`parallel` and
120+
:func:`.parallel_async.perform_parallel_async` for an example of this).
121121
122122
.. [#box] Without using one of those decorators, the performer is actually
123123
passed three arguments, not two: the dispatcher, the intent, and a

effect/_intents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ParallelEffects(object):
2626
An effect intent that asks for a number of effects to be run in parallel,
2727
and for their results to be gathered up into a sequence.
2828
29-
:func:`effect.async.perform_parallel_async` can perform this Intent
29+
:func:`effect.parallel_async.perform_parallel_async` can perform this Intent
3030
assuming all child effects have asynchronous performers.
3131
:func:`effect.threads.perform_parallel_with_pool` can perform blocking
3232
performers in a thread pool.

effect/async.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,2 @@
1-
"""Generic asynchronous performers."""
2-
3-
from functools import partial
4-
from itertools import count
5-
6-
from ._base import perform
7-
from ._intents import FirstError
8-
9-
10-
def perform_parallel_async(dispatcher, intent, box):
11-
"""
12-
A performer for :obj:`ParallelEffects` which works if all child Effects are
13-
already asynchronous. Use this for things like Twisted, asyncio, etc.
14-
15-
WARNING: If this is used when child Effects have blocking performers, it
16-
will run them in serial, not parallel.
17-
"""
18-
effects = list(intent.effects)
19-
if not effects:
20-
box.succeed([])
21-
return
22-
num_results = count()
23-
results = [None] * len(effects)
24-
25-
def succeed(index, result):
26-
results[index] = result
27-
if next(num_results) + 1 == len(effects):
28-
box.succeed(results)
29-
30-
def fail(index, result):
31-
box.fail((FirstError,
32-
FirstError(exc_info=result, index=index),
33-
result[2]))
34-
35-
for index, effect in enumerate(effects):
36-
perform(
37-
dispatcher,
38-
effect.on(
39-
success=partial(succeed, index),
40-
error=partial(fail, index)))
1+
from .parallel_async import perform_parallel_async
2+
__all__ = ['perform_parallel_async']

effect/parallel_async.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Generic asynchronous performers."""
2+
3+
from functools import partial
4+
from itertools import count
5+
6+
from ._base import perform
7+
from ._intents import FirstError
8+
9+
10+
def perform_parallel_async(dispatcher, intent, box):
11+
"""
12+
A performer for :obj:`ParallelEffects` which works if all child Effects are
13+
already asynchronous. Use this for things like Twisted, asyncio, etc.
14+
15+
WARNING: If this is used when child Effects have blocking performers, it
16+
will run them in serial, not parallel.
17+
"""
18+
effects = list(intent.effects)
19+
if not effects:
20+
box.succeed([])
21+
return
22+
num_results = count()
23+
results = [None] * len(effects)
24+
25+
def succeed(index, result):
26+
results[index] = result
27+
if next(num_results) + 1 == len(effects):
28+
box.succeed(results)
29+
30+
def fail(index, result):
31+
box.fail((FirstError,
32+
FirstError(exc_info=result, index=index),
33+
result[2]))
34+
35+
for index, effect in enumerate(effects):
36+
perform(
37+
dispatcher,
38+
effect.on(
39+
success=partial(succeed, index),
40+
error=partial(fail, index)))

effect/test_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ._base import Effect, perform
66
from ._dispatcher import ComposedDispatcher, TypeDispatcher
77
from ._intents import ParallelEffects, base_dispatcher, parallel
8-
from .async import perform_parallel_async
8+
from .parallel_async import perform_parallel_async
99
from .test_base import func_dispatcher
1010
from .test_parallel_performers import ParallelPerformerTestsMixin
1111

0 commit comments

Comments
 (0)