2023-05-18 18:08:38 +02:00
|
|
|
import structio
|
2023-05-19 16:38:59 +02:00
|
|
|
import tempfile
|
|
|
|
import os
|
2023-05-18 18:08:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
await structio.aprint("[main] Threaded async I/O is working!")
|
|
|
|
t = structio.clock()
|
|
|
|
stuff = await structio.ainput("Type something: ")
|
|
|
|
await structio.aprint(f"[main] Output from ainput(): {stuff}")
|
|
|
|
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
|
|
|
|
|
|
|
|
|
2023-05-19 16:38:59 +02:00
|
|
|
async def main_2(data: bytes):
|
|
|
|
t = structio.clock()
|
|
|
|
async with await structio.open_file(os.path.join(tempfile.gettempdir(), "structio_test.txt"), "wb+") as f:
|
|
|
|
print(f"[main] Opened async file {f.name!r}, writing payload of {len(data)} bytes")
|
|
|
|
await f.write(data)
|
|
|
|
await f.seek(0)
|
|
|
|
assert await f.read(len(data)) == data
|
2023-05-22 08:07:36 +02:00
|
|
|
await f.flush()
|
2023-05-19 16:38:59 +02:00
|
|
|
print(f"[main] Deleting {f.name!r}")
|
|
|
|
await structio.thread.run_in_worker(os.unlink, f.name)
|
2023-05-22 08:07:36 +02:00
|
|
|
assert not await structio.thread.run_in_worker(os.path.isfile, f.name)
|
2023-05-19 16:38:59 +02:00
|
|
|
print(f"[main] Done in {structio.clock() - t:.2f} seconds")
|
|
|
|
|
|
|
|
|
2023-05-22 08:07:36 +02:00
|
|
|
#structio.run(main)
|
|
|
|
MB = 1_048_576
|
|
|
|
GB = 1
|
|
|
|
# Write 1GB of data (too much?)
|
|
|
|
structio.run(main_2, b"a" * (GB * 1024 * MB))
|