Skip to main content

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

Metadata

Release files for dunsync 0.1.1

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

Source distribution (sdist)

Source distribution for dunsync 0.1.1
File Size Uploaded
dunsync-0.1.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dunsync 0.1.1
File Interpreter ABI Platform
dunsync-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / dunsync-0.1.1.tar.gz

Download URL dunsync-0.1.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3fa8e2209900e5b75e3ded94ade47fc7253c85519e4900ff4187169e8f7f1328
BLAKE2b-256 checksum
How to use checksums
877c421d27d89de2a7638445783283cafca796ca06643ca7bb662d241adacf5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

Release files / dunsync-0.1.1-py3-none-any.whl

Download URL dunsync-0.1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87e7e66227f83ad359f72f9a407a40447f30374ed2de45a61586b6ab963c6044
BLAKE2b-256 checksum
How to use checksums
1ddf915d778cf052938009a7cb466c357b8c163d9fd68598cc21651fbbc04965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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