File: test_async.py

package info (click to toggle)
python-memory-profiler 0.61-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 540 kB
  • sloc: python: 2,220; makefile: 33
file content (27 lines) | stat: -rw-r--r-- 597 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asyncio
import sys

from memory_profiler import profile


@profile
async def my_func():
    a = [1] * (10 ** 6)
    b = [2] * (2 * 10 ** 7)
    await asyncio.sleep(1e-2)
    del b

async def main():
    task = asyncio.create_task(my_func())
    res = await asyncio.gather(task)

async def main_legacy():
    future = asyncio.ensure_future(my_func())
    res = await asyncio.gather(future)

if __name__ == '__main__':
    if sys.version_info >= (3, 7):
        asyncio.run(main())  # main loop
    else:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(main_legacy())