Skip to content

Commit c3a30af

Browse files
committed
Fix usages of spawn_n and map_n in tests and readme
1 parent b1a8138 commit c3a30af

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def spawn_n_usage(todo=[range(1,51), range(51,101), range(101,200)]):
7272
# Returns quickly for all tasks, does not wait for pool space.
7373
# Workers are not spawned, they wait for pool space in their
7474
# own background tasks.
75-
fut = await pool.spawn_n(worker(i))
75+
fut = pool.spawn_n(worker(i))
7676
futures.append(fut)
7777
# At this point not a single worker should start.
7878

@@ -147,7 +147,7 @@ async def callbacks_usage():
147147

148148
async with AioPool(size=2) as pool:
149149
for i in todo:
150-
fut = await pool.spawn_n(wrk(i), cb, (pool, i))
150+
fut = pool.spawn_n(wrk(i), cb, (pool, i))
151151
futures.append(fut)
152152

153153
results = []
@@ -173,7 +173,7 @@ async def callbacks_usage():
173173

174174
async def exec_usage(todo=range(1,11)):
175175
async with AioPool(size=4) as pool:
176-
futures = await pool.map_n(worker, todo)
176+
futures = pool.map_n(worker, todo)
177177

178178
# While other workers are waiting or active, you can "synchronously"
179179
# execute one task. It does not interrupt others, just waits for pool
@@ -195,9 +195,9 @@ async def cancel_usage():
195195

196196
pool = AioPool(size=2)
197197

198-
f_quick = await pool.spawn_n(aio.sleep(0.1))
199-
f12 = await pool.spawn(wrk()), await pool.spawn_n(wrk())
200-
f35 = await pool.map_n(wrk, range(3))
198+
f_quick = pool.spawn_n(aio.sleep(0.1))
199+
f12 = await pool.spawn(wrk()), pool.spawn_n(wrk())
200+
f35 = pool.map_n(wrk, range(3))
201201

202202
# At this point, if you cancel futures, returned by pool methods,
203203
# you just won't be able to retrieve spawned task results, task
@@ -232,9 +232,9 @@ async def details(todo=range(1,11)):
232232
# This code:
233233
f1 = []
234234
for i in todo:
235-
f1.append(await pool.spawn_n(worker(i)))
235+
f1.append(pool.spawn_n(worker(i)))
236236
# is equivalent to one call of `map_n`:
237-
f2 = await pool.map_n(worker, todo)
237+
f2 = pool.map_n(worker, todo)
238238

239239
# Afterwards you can await for any given future:
240240
try:

asyncio_pool/mx_asyncgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def itermap(self, fn, iterable, cb=None, ctx=None, *, flat=True,
3737
'''Spawns coroutines created with `fn` for each item in `iterable`, then
3838
waits for results with `iterwait`. See docs for `map_n` and `iterwait`.
3939
'''
40-
futures = await self.map_n(fn, iterable, cb, ctx)
40+
futures = self.map_n(fn, iterable, cb, ctx)
4141
generator = iterwait(futures, flat=flat, timeout=timeout,
4242
get_result=get_result, yield_when=yield_when, loop=self.loop)
4343
async for batch in generator:

asyncio_pool/mx_asynciter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __aiter__(_self):
6060

6161
async def __anext__(_self):
6262
if not hasattr(_self, 'waiter'):
63-
_self.waiter = mk_waiter(await mk_map())
63+
_self.waiter = mk_waiter(mk_map())
6464
return await _self.waiter.__anext__()
6565

6666
return _itermap()

examples/_usage.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def spawn_n_usage(todo=[range(1,51), range(51,101), range(101,200)]):
2424
# Returns quickly for all tasks, does not wait for pool space.
2525
# Workers are not spawned, they wait for pool space in their
2626
# own background tasks.
27-
fut = await pool.spawn_n(worker(i))
27+
fut = pool.spawn_n(worker(i))
2828
futures.append(fut)
2929
# At this point not a single worker should start.
3030

@@ -99,7 +99,7 @@ async def cb(res, err, ctx): # callback
9999

100100
async with AioPool(size=2) as pool:
101101
for i in todo:
102-
fut = await pool.spawn_n(wrk(i), cb, (pool, i))
102+
fut = pool.spawn_n(wrk(i), cb, (pool, i))
103103
futures.append(fut)
104104

105105
results = []
@@ -125,7 +125,7 @@ async def cb(res, err, ctx): # callback
125125

126126
async def exec_usage(todo=range(1,11)):
127127
async with AioPool(size=4) as pool:
128-
futures = await pool.map_n(worker, todo)
128+
futures = pool.map_n(worker, todo)
129129

130130
# While other workers are waiting or active, you can "synchronously"
131131
# execute one task. It does not interrupt others, just waits for pool
@@ -147,9 +147,9 @@ async def wrk(*arg, **kw):
147147

148148
pool = AioPool(size=2)
149149

150-
f_quick = await pool.spawn_n(aio.sleep(0.1))
151-
f12 = await pool.spawn(wrk()), await pool.spawn_n(wrk())
152-
f35 = await pool.map_n(wrk, range(3))
150+
f_quick = pool.spawn_n(aio.sleep(0.1))
151+
f12 = await pool.spawn(wrk()), pool.spawn_n(wrk())
152+
f35 = pool.map_n(wrk, range(3))
153153

154154
# At this point, if you cancel futures, returned by pool methods,
155155
# you just won't be able to retrieve spawned task results, task
@@ -184,15 +184,15 @@ async def details(todo=range(1,11)):
184184
# This code:
185185
f1 = []
186186
for i in todo:
187-
f1.append(await pool.spawn_n(worker(i)))
187+
f1.append(pool.spawn_n(worker(i)))
188188
# is equivalent to one call of `map_n`:
189-
f2 = await pool.map_n(worker, todo)
189+
f2 = pool.map_n(worker, todo)
190190

191191
# Afterwards you can await for any given future:
192192
try:
193193
assert 3 == await f1[2] # result of spawn_n(worker(3))
194-
except Exception as e:
195-
# exception happened in worker (or CancelledError) will be re-raised
194+
except BaseException:
195+
# exception happened in worker (including CancelledError) will be re-raised
196196
pass
197197

198198
# Or use `asyncio.wait` to handle results in batches (see `iterwait` also):

tests/loadtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def loadtest_spawn_n(tasks, pool_size, duration):
2525
futures = []
2626
async with AioPool(size=pool_size) as pool:
2727
for i in range(tasks):
28-
fut = await pool.spawn_n(aio.sleep(duration))
28+
fut = pool.spawn_n(aio.sleep(duration))
2929
futures.append(fut)
3030

3131
return [getres.flat(f) for f in futures]

tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def outer(n, pool):
7070
loop = aio.get_event_loop()
7171
pool = AioPool(size=100)
7272

73-
tasks = pool.map_n(inner, todo)
73+
pool.map_n(inner, todo)
7474
joined = [loop.create_task(outer(j, pool)) for j in to_release]
7575
await pool.join()
7676

tests/test_callbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def test_spawn_n():
3131
async with AioPool(size=2) as pool:
3232
for i in todo:
3333
ctx = (pool, i)
34-
fut = await pool.spawn_n(wrk(i), cb, ctx)
34+
fut = pool.spawn_n(wrk(i), cb, ctx)
3535
futures.append(fut)
3636

3737
results = [getres.flat(f) for f in futures]
@@ -52,7 +52,7 @@ async def test_map():
5252
async def test_map_n():
5353
todo = range(2,11)
5454
async with AioPool(size=3) as pool:
55-
futures = await pool.map_n(wrk, todo, cb)
55+
futures = pool.map_n(wrk, todo, cb)
5656

5757
results = [getres.flat(f) for f in futures]
5858
assert 2 * sum(todo) == sum(results)

tests/test_spawn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def wrk(n):
2727

2828
async with AioPool(size=2) as pool:
2929
for i in range(1,6):
30-
await pool.spawn_n(wrk(i)) # does not wait for pool, just spawns waiting coros
30+
pool.spawn_n(wrk(i)) # does not wait for pool, just spawns waiting coros
3131
assert len(started) == 0 # so atm no worker should be able to start
3232

3333

0 commit comments

Comments
 (0)