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)
Built Distribution
Close
Hashes for process_decorator-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfcec425031651aa32b4fcd239bf7b2eda53740ddfc69064ea0009c6d36309c0 |
|
MD5 | c8a8ba5cf9f1c5575221742ca47c6484 |
|
BLAKE2b-256 | cc30d1382b6fbf8e2a6d99ac04215179cd18a3a3d7412443b8bdfc73cc181e97 |