Skip to main content

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.

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 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(result):
    '''
    Parameter "result" is the return from task.
    Use functools.partial() to give arguments if you need more args at the beginning.
    '''
    print('-* callback *-')
    print(result)

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

go(task_1)
go(task_2)

# The "callback" parameter must be specified separately.
go(task_1, 5, callback = callback)
go(task_2, 3, callback = callback)
print('END')

# Forever runing to show results.
while 1:
    time.sleep(5)

Output :

>>>
END
Task_2_done
Task_1_done
Task_2_done
-* callback *-
Result_2
Task_1_done
-* callback *-
Result_1

License

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

Release files for goroutine-py 1.0.9

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

Source distribution (sdist)

Source distribution for goroutine-py 1.0.9
File Size Uploaded
goroutine_py-1.0.9.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for goroutine-py 1.0.9
File Interpreter ABI Platform
goroutine_py-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / goroutine_py-1.0.9.tar.gz

Download URL goroutine_py-1.0.9.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e221d647fbd154a1253bea640311d9b12362a9f7cbaee661deda363ba5ef8dea
BLAKE2b-256 checksum
How to use checksums
de51244b3a4d8275cd68ee9f3d3f4f8e8465f0d06780ece4da067a6bc0407b6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Release files / goroutine_py-1.0.9-py3-none-any.whl

Download URL goroutine_py-1.0.9-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1671fd83e9bbf524ba3a433420ecf6916970492126dd973b989f427d36201673
BLAKE2b-256 checksum
How to use checksums
ce33248db7f67599f22711364684c3e75863873ffee0aab8c723bf275d832e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.2

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