Skip to main content

make func async and execute in other process

Project description

process_decorator

If you write async code, you now that all code work on one processor (tnx GIL), but we can resolve this problem with execution code in other process.

ATTENTION, we get profit only if function work more than 0.1 sec or if you need make async function. AND don't work global variable, because func work in other process

from process_decorator import async_process
import asyncio

@async_process()
def test():
    return 2*500000000

if __name__ == '__main__':
    asyncio.run(test())

this code creates other process where will be executed.

async_process get argument exit_process_timer, witch cache process on time executed. If you call this function every time, this parameter will up speed of execution

from process_decorator import async_process
import asyncio

@async_process(exit_process_timer=10)
def test():
    return 2*50000000

if __name__ == '__main__':
    for _ in range(30):
        asyncio.run(test())
where:

exit_process_timer - is time in second when process close if wont call

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

process_decorator-0.4.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

process_decorator-0.4-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page