Skip to main content

qaviton io

Project description

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 requests import get  # lets make use of requests to make async http calls
from qaviton_io import AsyncManager, task


# 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
@task(exceptions=Exception)
def task(): return get("https://qaviton.com")


# 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)])

# we can assert the collected results here
assert len(m.results) == 21
for r in m.results:
    assert r.status_code == 200

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

process manager:

"""
make sure your tasks are defined at the module level,
so they can be pickled by multiprocessing
"""
from time import time
from requests import get
from qaviton_io.types import Tasks
from qaviton_io import ProcessManager, task
from traceback import format_exc


# 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
@task()
def task1(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
@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
    ]:
        task1(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

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

qaviton_io-2019.11.8.10.10.6.714465.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qaviton_io-2019.11.8.10.10.6.714465-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file qaviton_io-2019.11.8.10.10.6.714465.tar.gz.

File metadata

  • Download URL: qaviton_io-2019.11.8.10.10.6.714465.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for qaviton_io-2019.11.8.10.10.6.714465.tar.gz
Algorithm Hash digest
SHA256 b3061b21eef4cb0e104a603e3ae11c1344ccbca19094bb35c141a6ccaa667a2f
MD5 d20a7002db955d21a69a40e513c58112
BLAKE2b-256 7935169c55a100d62621c3666e14a062f6a6300edf9a469342a4c72ebf8165b4

See more details on using hashes here.

File details

Details for the file qaviton_io-2019.11.8.10.10.6.714465-py2.py3-none-any.whl.

File metadata

  • Download URL: qaviton_io-2019.11.8.10.10.6.714465-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for qaviton_io-2019.11.8.10.10.6.714465-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 662de1b2b14844121d659ce316c487b9a78755b1d6fea5e0b89fa51e8632ae37
MD5 d5dbb073b24f3712b85d2bd39c6ea609
BLAKE2b-256 6322032b0b15fdaf50804e3982e12ed636730baa3d0a55922318827974228ead

See more details on using hashes here.

Supported by

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