| 1 |
import asyncio |
| 2 |
from caio import AsyncioContext |
| 3 |
|
| 4 |
|
| 5 |
loop = asyncio.get_event_loop() |
| 6 |
|
| 7 |
|
| 8 |
async def main(): |
| 9 |
# max_requests=128 by default |
| 10 |
ctx = AsyncioContext(max_requests=128) |
| 11 |
|
| 12 |
with open("test.file", "wb+") as fp: |
| 13 |
fd = fp.fileno() |
| 14 |
|
| 15 |
# Execute one write operation |
| 16 |
await ctx.write(b"Hello world", fd, offset=0) |
| 17 |
|
| 18 |
# Execute one read operation |
| 19 |
print(await ctx.read(32, fd, offset=0)) |
| 20 |
|
| 21 |
# Execute one fdsync operation |
| 22 |
await ctx.fdsync(fd) |
| 23 |
|
| 24 |
op1 = ctx.write(b"Hello from ", fd, offset=0) |
| 25 |
op2 = ctx.write(b"async world", fd, offset=11) |
| 26 |
|
| 27 |
await asyncio.gather(op1, op2) |
| 28 |
|
| 29 |
print(await ctx.read(32, fd, offset=0)) |
| 30 |
# Hello from async world |
| 31 |
|
| 32 |
|
| 33 |
loop.run_until_complete(main()) |