Skip to main content

Qaviton IO

logo
version license open issues downloads code size

Qaviton IO
is a package with a simple API, making use of python's async & multiprocessing
to enable fast execution of many asyncable operations.

Installation

pip install qaviton-io -U

Requirements

  • Python 3.6+

Features

  • async task manager
  • process task manager
  • task logger

Usage

async manager:

from time import time
from typing import List
from requests import get, Response  # lets make use of requests to make async http calls
from qaviton_io import AsyncManager

# we can save the responses here
rs: List[Response] = []

# let's create an async manager
m = AsyncManager()


# first we make a simple function to make an http call.
# we want to log the result,
# and make sure that in case of an exception
# the manager won't stop
@m.log.task(exceptions=Exception)
def task():
    r = get("https://qaviton.com")
    r.raise_for_status()
    rs.append(r)


# this will run async tasks and measure their duration
def run(tasks):
    t = time()
    m.run(tasks)
    t = time() - t
    print(f'took {round(t, 3)}s')


# let's run our task once and see how long it takes
run([task for _ in range(1)])

# now let's run our task 20 times and see how long it takes
run([task for _ in range(20)])

# let's view the results in the log report
m.log.report()

process manager:

from time import time
from requests import get
from qaviton_io.types import Tasks
from qaviton_io import ProcessManager, Log
from traceback import format_exc

# make sure your tasks are defined at the module level,
# so they can be pickled by multiprocessing

# first we need to make a log registry
log = Log()


# now we make some tasks
# this is a nested task
# we don't want to handle any exceptions
# so in case of failure the parent will not proceed
@log.task()
def task(url):
    r = get(url)
    r.raise_for_status()


# this is the prent task
# we want to handle all exceptions
# so in case of failure the next task will execute
@log.task(exceptions=Exception)
def multi_task():
    for url in [
        "https://qaviton.com",
        "https://qaviton.co.il",  # make sure you enter a valid address
        "https://qaviton.com1",  # make sure you enter a valid address
    ]:
        task(url)


# let's create a function to execute tasks
def execute_tasks(tasks: Tasks, timeout):
    manager = ProcessManager()
    t = time()
    try:
        manager.run_until_complete(tasks, timeout=timeout)
        timed_out = None
    except TimeoutError:
        timed_out = format_exc()
    t = time() - t
    manager.log.report()
    print(f'took {round(t, 3)}s\n')
    manager.log.clear()
    return timed_out


# now all that's left is to run the tasks
if __name__ == "__main__":
    timeouts = [
        execute_tasks([multi_task for _ in range(1)], timeout=3),
        execute_tasks([multi_task for _ in range(20)], timeout=6),
        execute_tasks([multi_task for _ in range(80)], timeout=9),
    ]
    for timeout in timeouts:
        if timeout:
            print(timeout)

notes:

  • for good performance and easy usage
    you should probably stick with using the AsyncManager

  • The ProcessManager uses async operations as well as multi-processing.
    It distributes tasks across cpus, and those tasks are executed using the AsyncManager
    if you want maximum efficiency you should consider using the ProcessManager

  • The ProcessManager uses the multiprocessing module
    and should be treated with it's restrictions & limitations accordingly

  • The ProcessManager gets stuck easily,
    make sure to use timeouts when using it

Metadata

Release files for qaviton-io 2019.11.3.17.39.58.419954

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qaviton-io 2019.11.3.17.39.58.419954
File Size Uploaded Provenance Actions
qaviton_io-2019.11.3.17.39.58.419954.tar.gz 5.7 kB Without provenance Details for qaviton_io-2019.11.3.17.39.58.419954.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qaviton-io 2019.11.3.17.39.58.419954
File Interpreter ABI Platform Actions
qaviton_io-2019.11.3.17.39.58.419954-py2.py3-none-any.whl Python 2, Python 3 none any Details for qaviton_io-2019.11.3.17.39.58.419954-py2.py3-none-any.whl

Total release size: 16.8 kB

Release files / qaviton_io-2019.11.3.17.39.58.419954.tar.gz

Download URL qaviton_io-2019.11.3.17.39.58.419954.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9dfc0e7f2b17c65de4d715b6ce2f20a3bd280e5c0582a5f5548d4d8534913328
BLAKE2b-256 checksum
How to use checksums
9f168d44df114f0407955c689c62ab31a9aee815340a103b430c891decac4df8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

Release files / qaviton_io-2019.11.3.17.39.58.419954-py2.py3-none-any.whl

Download URL qaviton_io-2019.11.3.17.39.58.419954-py2.py3-none-any.whl
Size 11.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7fd93634b379dc8f58f49d3b625c849a9f8ebde3871e7a5eee2e1db4950f1c05
BLAKE2b-256 checksum
How to use checksums
ec993a3ec740f67f3fa1f85e8aadf5a42e3582dd6cd5f32444fb8f59221d75db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

Security for qaviton-io 2019.11.3.17.39.58.419954

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page