async-decorator


Nameasync-decorator JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/FadsII/async-decorator
SummaryA flexible async/sync execution library with dedicated thread pools
upload_time2025-11-03 06:28:12
maintainerNone
docs_urlNone
authorFadsII
requires_python>=3.8
licenseMIT
keywords async threading executor decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Async Decorator

A flexible Python library for managing async/sync function execution with dedicated thread pools.

## Features

- **Dedicated Thread Pools**: Isolate synchronous function execution
- **Shared Thread Pools**: Efficiently execute async functions in threads  
- **Flexible Execution Types**: EXCLUSIVE, SHARED_POOL
- **Thread Safety**: Managed thread pool lifecycle
- **Easy Integration**: Simple decorator-based API

## Installation

```bash
pip install async-decorator
```

## Quick Start

```python
import asyncio
import aiohttp
from async_decorator import async_decorator, ExecType

@async_decorator(ExecType.EXCLUSIVE)
def process_data(data):
    # CPU-intensive synchronous work
    return len(data)

@async_decorator(ExecType.SHARED_POOL)
async def fetch_data(url):
    # I/O-bound async work
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.text()

async def main():
    # These run in appropriate thread pools
    result1 = process_data("hello world")
    result2 = await fetch_data("https://example.com")
    
    print(f"Processed: {result1}, Fetched: {len(result2)} bytes")

asyncio.run(main())
```

## Execution Types

- `EXCLUSIVE`: Sync functions in dedicated thread pools
- `SHARED_POOL`: Async functions in shared thread pool

## Advanced Usage

### Example 1 

```python
from async_decorator import ExecType, async_decorator

# Custom maximum workers for shared async pool
shared_pool_size = 200

@async_decorator(ExecType.SHARED_POOL, shared_pool_size=shared_pool_size)
def custom_processing():
    return "processed"

```

### Example 2

```python
from async_decorator import DedicatedThreadManager, ExecType, async_decorator

# Custom thread manager, but shared_pool_size will lose its effect
manager = DedicatedThreadManager(
    shared_pool_size=20,
    max_dedicated_pools=50
)

@async_decorator(ExecType.EXCLUSIVE, "my_exclusive", thread_manager=manager)
def custom_processing():
    return "processed"

# Cleanup
manager.shutdown()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/FadsII/async-decorator",
    "name": "async-decorator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "async, threading, executor, decorator",
    "author": "FadsII",
    "author_email": "FadsII <594604366@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/91/5b/08bf402a120b6d4f8c97b012e7092384c27e886ad10c23f4c5c0c28f2569/async_decorator-0.1.0.tar.gz",
    "platform": null,
    "description": "# Async Decorator\r\n\r\nA flexible Python library for managing async/sync function execution with dedicated thread pools.\r\n\r\n## Features\r\n\r\n- **Dedicated Thread Pools**: Isolate synchronous function execution\r\n- **Shared Thread Pools**: Efficiently execute async functions in threads  \r\n- **Flexible Execution Types**: EXCLUSIVE, SHARED_POOL\r\n- **Thread Safety**: Managed thread pool lifecycle\r\n- **Easy Integration**: Simple decorator-based API\r\n\r\n## Installation\r\n\r\n```bash\r\npip install async-decorator\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nimport asyncio\r\nimport aiohttp\r\nfrom async_decorator import async_decorator, ExecType\r\n\r\n@async_decorator(ExecType.EXCLUSIVE)\r\ndef process_data(data):\r\n    # CPU-intensive synchronous work\r\n    return len(data)\r\n\r\n@async_decorator(ExecType.SHARED_POOL)\r\nasync def fetch_data(url):\r\n    # I/O-bound async work\r\n    async with aiohttp.ClientSession() as session:\r\n        async with session.get(url) as response:\r\n            return await response.text()\r\n\r\nasync def main():\r\n    # These run in appropriate thread pools\r\n    result1 = process_data(\"hello world\")\r\n    result2 = await fetch_data(\"https://example.com\")\r\n    \r\n    print(f\"Processed: {result1}, Fetched: {len(result2)} bytes\")\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n## Execution Types\r\n\r\n- `EXCLUSIVE`: Sync functions in dedicated thread pools\r\n- `SHARED_POOL`: Async functions in shared thread pool\r\n\r\n## Advanced Usage\r\n\r\n### Example 1 \r\n\r\n```python\r\nfrom async_decorator import ExecType, async_decorator\r\n\r\n# Custom maximum workers for shared async pool\r\nshared_pool_size = 200\r\n\r\n@async_decorator(ExecType.SHARED_POOL, shared_pool_size=shared_pool_size)\r\ndef custom_processing():\r\n    return \"processed\"\r\n\r\n```\r\n\r\n### Example 2\r\n\r\n```python\r\nfrom async_decorator import DedicatedThreadManager, ExecType, async_decorator\r\n\r\n# Custom thread manager, but shared_pool_size will lose its effect\r\nmanager = DedicatedThreadManager(\r\n    shared_pool_size=20,\r\n    max_dedicated_pools=50\r\n)\r\n\r\n@async_decorator(ExecType.EXCLUSIVE, \"my_exclusive\", thread_manager=manager)\r\ndef custom_processing():\r\n    return \"processed\"\r\n\r\n# Cleanup\r\nmanager.shutdown()\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A flexible async/sync execution library with dedicated thread pools",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/FadsII/async-decorator#readme",
        "Homepage": "https://github.com/FadsII/async-decorator",
        "Issues": "https://github.com/FadsII/async-decorator/issues",
        "Repository": "https://github.com/FadsII/async-decorator"
    },
    "split_keywords": [
        "async",
        " threading",
        " executor",
        " decorator"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "54e8be0e719ecda3421fd34fd279da9c1e71d43d42f051cc3e2cea43b0f37804",
                "md5": "5539237f95b5a31d45a28bb8f572a508",
                "sha256": "852dc9ead0dc7d9e46772f6bbbef19f8aca88c1797516984764c34f6c3db0721"
            },
            "downloads": -1,
            "filename": "async_decorator-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5539237f95b5a31d45a28bb8f572a508",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7803,
            "upload_time": "2025-11-03T06:28:10",
            "upload_time_iso_8601": "2025-11-03T06:28:10.611572Z",
            "url": "https://files.pythonhosted.org/packages/54/e8/be0e719ecda3421fd34fd279da9c1e71d43d42f051cc3e2cea43b0f37804/async_decorator-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "915b08bf402a120b6d4f8c97b012e7092384c27e886ad10c23f4c5c0c28f2569",
                "md5": "73d87e10ab9db63ed5d74830eeb774d0",
                "sha256": "29e7d019aebfb07ae4e46f375040accb595b8a663f022adacc80734c987b4c4f"
            },
            "downloads": -1,
            "filename": "async_decorator-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "73d87e10ab9db63ed5d74830eeb774d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7386,
            "upload_time": "2025-11-03T06:28:12",
            "upload_time_iso_8601": "2025-11-03T06:28:12.246896Z",
            "url": "https://files.pythonhosted.org/packages/91/5b/08bf402a120b6d4f8c97b012e7092384c27e886ad10c23f4c5c0c28f2569/async_decorator-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-03 06:28:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "FadsII",
    "github_project": "async-decorator",
    "github_not_found": true,
    "lcname": "async-decorator"
}
        
Elapsed time: 1.08856s