toasync
Convert sync function to async function and start at same time
from time import sleep, time
import asyncio
from toasync import async_
@async_
def func(name, i=1):
print('Start function {}'.format(name))
sleep(1)
print('Done function {}'.format(name))
if __name__ == '__main__':
coroutine = asyncio.gather(
func()('1'),
func()('2'),
func()('3'),
)
start_time = time()
asyncio.get_event_loop().run_until_complete(coroutine)
print('Process take {} sencond'.format(time-start_time))
then
Start function 1
Start function 2
Start function 3
Done function 2
Done function 1
Done function 3
Process take 1.007418155670166 sencond
If run function as synchronous, you can call delay method
from time import sleep
from toasync import async_
@async_
def func(name, i=1):
print('Start function {}'.format(name))
sleep(1)
print('Done function {}'.format(name))
if __name__ == '__main__':
func().delay('1')
func().delay('2')
func().delay('3')
then
Start function 1
Done function 1
Start function 2
Done function 2
Start function 3
Done function 3
Metadata
Release files for toasync 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toasync-0.0.1.tar.gz | 1.6 kB | Without provenance | Details for toasync-0.0.1.tar.gz |
Release files / toasync-0.0.1.tar.gz
| Download URL | toasync-0.0.1.tar.gz |
|---|---|
| Size | 1.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f7ce3ec70c8536d25d413cd5ce12c5394d8d72a9c47ca96ea047e5faded8b73
|
|
BLAKE2b-256 checksum How to use checksums |
18973343ebe25198e4ebecc2ef2eca47792e593693325c42aed1a16fcd2aafc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for toasync 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.