Skip to main content

No project description provided

Project description

Mechanicus

Parallel execute with asyncio library

Install

pip3 install mechanicus

Dependencies

  • python >=3.7
  • aiohttp
  • aiofiles

Examples

Parallel file download

executor = QueueExecutor(Downloader())
await executor.execute([
    DownloadTask(
        "https://file-examples-com.github.io/uploads/2017/02/file_example_CSV_5000.csv",
        "/home/user/Downloads/example.csv",
    ),
    DownloadTask(
        "https://file-examples-com.github.io/uploads/2017/02/file_example_JSON_1kb.json",
        "/home/user/Downloads/example.json",
    )
])

Parallel custom task execute

async def source(count):
    for i in range(count):
        print(f"new: {i}")
        yield i
        await asyncio.sleep(0.2)

class CustomExecutor(TaskExecutor[int, int]):
    async def execute(self, task: int):
        print(f"start: {task}")
        await asyncio.sleep(0.5)
        print(f"complete: {task}")
        return task

executor = QueueExecutor(CustomExecutor())
result = await executor.execute(source(20))
print(f"result: {result}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mechanicus-0.0.2.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

mechanicus-0.0.2-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page