asyncio-executor
Project description
version: 0.0.3
status: dev
author: hsz
email: hsz1273327@gmail.com
Desc
Asyncio executor for running coroutines. This code is from <https://gist.github.com/seglberg/0b4487b57b4fd425c56ad72aba9971be>
keywords:asyncio,executor
Feature
run coroutines asynchronously
Example
run coroutines by using submit
from concurrent.futures import as_completed
import aiohttp
from asyncio_executor import AsyncioExecutor
async def httpget(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
html = await resp.text("utf-8")
return len(html)
with AsyncioExecutor() as executor:
to_do = []
urls = ["https://github.com/","https://docs.aiohttp.org/"]
for i in urls:
job = executor.submit(httpget,i)
to_do.append(job)
for future in as_completed(to_do):
res = future.result()
run coroutines by using map
from concurrent.futures import as_completed
import aiohttp
from asyncio_executor import AsyncioExecutor
async def httpget(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
html = await resp.text("utf-8")
return len(html)
with AsyncioExecutor() as executor:
result = []
urls = ["https://github.com/", "https://docs.aiohttp.org/"]
for i in executor.map(httpget, urls):
result.append(i)
run functions by using submit
from concurrent.futures import as_completed
import requests as rq
from asyncio_executor import AsyncioExecutor
def httpsync(url):
req = rq.get(url)
return len(req.text)
with AsyncioExecutor() as executor:
to_do = []
urls = ["https://github.com/", "https://docs.aiohttp.org/"]
for i in urls:
job = executor.submit(httpsync, i)
to_do.append(job)
for future in as_completed(to_do):
res = future.result()
print(res)
run functions by using map
from concurrent.futures import as_completed
import requests as rq
from asyncio_executor import AsyncioExecutor
def httpsync(url):
req = rq.get(url)
return len(req.text)
with AsyncioExecutor() as executor:
result = []
urls = ["https://github.com/", "https://docs.aiohttp.org/"]
for i in executor.map(httpsync, urls):
result.append(i)
print(result)
Install
python -m pip install asyncio-executor
Limitations
only support python 3.5+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file asyncio-executor-0.0.3.tar.gz
.
File metadata
- Download URL: asyncio-executor-0.0.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4026f22e22369be373227106d6eacb11d46fcc8982b530995dd67d88fcca3533 |
|
MD5 | e5b5aab9a33802f12ad6ae5db5798d2c |
|
BLAKE2b-256 | 7e805b582e217bc5bb8d97736c4af671051f3510dd5c885876dec28e6e596f29 |
File details
Details for the file asyncio_executor-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: asyncio_executor-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c08b41cc060b0ff24ee7daac8baac97c2e74e6d3f08b83fcd1342e23004298e |
|
MD5 | 4cf570bbcbb775089f637ef51786ae08 |
|
BLAKE2b-256 | 888c683f0c1427705c986eba3717f218a8051c72cc32718ebf2abf252f99701e |