Skip to main content

Identical to unsync, but supports cpu-bound continuation functions

Project description

dunsync

Identical to unsync, except that continuation callbacks receives the result of the Unfuture rather than the Unfuture itself. This allows cpu-bound @unsync functions to be chained together with other regular functions and IO-bound @unsync functions, as long as the result is pickleble.

Example

from dunsync import unsync
import asyncio
import time

@unsync()  # Will run in an asyncio event loop
async def download_data(url):
    await asyncio.sleep(1)
    return 'data'

@unsync(cpu_bound=True)  # Will run in a separate process
def process_data(data):
    time.sleep(1)
    return 'processed data'

@unsync()  # Will run in a separate thread
def store_processed_data(data):
    time.sleep(1)
    return 'Done'

tasks = [
    download_data(url).then(process_data).then(store_processed_data)
    for url in ['url1', 'url2', 'url3']
]

for task in tasks:
    print(task.result())

Replacing dunsync with unsync in the above example results in the error TypeError: cannot pickle '_asyncio.Task' object, since the Unfuture wraps other objects (either asyncio.Task, as in this example, or threading.Thread) which cannot be pickled in order to be passed to a separate process.

Installation

Using pip:

pip install dunsync

Using pipenv:

pipenv install dunsync

Using poetry:

poetry add dunsync

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

dunsync-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

dunsync-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file dunsync-0.1.1.tar.gz.

File metadata

  • Download URL: dunsync-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

File hashes

Hashes for dunsync-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3fa8e2209900e5b75e3ded94ade47fc7253c85519e4900ff4187169e8f7f1328
MD5 07c275bfb184ede7674d3c888b3d945b
BLAKE2b-256 877c421d27d89de2a7638445783283cafca796ca06643ca7bb662d241adacf5e

See more details on using hashes here.

File details

Details for the file dunsync-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dunsync-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

File hashes

Hashes for dunsync-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87e7e66227f83ad359f72f9a407a40447f30374ed2de45a61586b6ab963c6044
MD5 af7b461e904d319cde4c5482c5b9d9bb
BLAKE2b-256 1ddf915d778cf052938009a7cb466c357b8c163d9fd68598cc21651fbbc04965

See more details on using hashes here.

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