Skip to main content

An Asyncio-based concurrency library for Python.

Project description

English | 中文

goroutine-py

🚀 An Asyncio-based concurrency library for Python.

​ Easy concurrency just like goroutine without worry about thread and coroutine in Python.

Introduction

Withing goroutine.app.go you can run a coroutine or a func asynchronously.

Main function go :

go (obj: callable, *args, callback: callable = None, lock: bool = False)

obj: Takes both callable coroutinefunction and func as object.

*args: Arguments for your obj.

callback: Attaches a callable that will be called when the future finishes.

lock: Thread safe if True. It can slow your program.

​ This argument only work for "func" not "coroutinefunction".

Getting Started

Support:

Python 3.7 / 3.8 / 3.9 / 3.10 / 3.11 / 3.12

Installation

First you have to install goroutine-py like this:

pip install goroutine-py

Quick Tutorial

The primary entity of goroutine-py is goroutine.app.go. You can simply start using goroutine-py like this:

First, define your tasks:

import asyncio
import functools
import time
from goroutine.app import go

# A normal func
def task_1(n=2):
    time.sleep(n)
    print('Task_1_done')
    return 'Result_1'
# A coroutinefunction
async def task_2(n=1):
    await asyncio.sleep(n)
    print('Task_2_done')
    return 'Result_2'
# Callback func
def callback(future, arg=None):
    '''
    At least ONE Parameter "future" is required.
    This future is a concurrent.futures.Future.
    Use functools.partial() to give arguments for your callback func.
    '''
    print(future.result(),arg)

After you defined all your tasks and callback, you can go like this:

go(task_1)
go(task_2)
go(task_1, 4, callback=callback)
go(task_2, 2, callback=functools.partial(callback,arg='a'))
print('END')

Output :

>>>
END
Task_2_done
Task_1_done
Task_2_done
Result_2 a
Task_1_done
Result_1 None

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

goroutine_py-1.0.8.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

goroutine_py-1.0.8-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file goroutine_py-1.0.8.tar.gz.

File metadata

  • Download URL: goroutine_py-1.0.8.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.1

File hashes

Hashes for goroutine_py-1.0.8.tar.gz
Algorithm Hash digest
SHA256 54c4f1cf00dc8f30d13ac9a1f0ede019f6064f2819cd30457bc85e5a0936cefe
MD5 11ff5ec04aa6a32e50e2fcab0b84c55f
BLAKE2b-256 694d93fc823271f1454f7c9982c1656d60fa36d8959fba13c4b6f8328b1421c1

See more details on using hashes here.

File details

Details for the file goroutine_py-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: goroutine_py-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.1

File hashes

Hashes for goroutine_py-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bebcb7d7483d7239a282e505af54ec153f97154c7613aa5bb3f21bef00fef8a2
MD5 601e9a9ef718ec47a4dea29047d55fbd
BLAKE2b-256 6a3098999811dcdf5032d7367680d588b0b62394e8ef30342939290fd5ed3470

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