forked from chyld/asyncio-summer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncread_c.py
More file actions
39 lines (26 loc) · 854 Bytes
/
asyncread_c.py
File metadata and controls
39 lines (26 loc) · 854 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
import sys
from pathlib import Path
import aiofiles
async def follow(rawfn):
cleanfn = Path(rawfn).name
fnpath = Path().cwd() / cleanfn
if not fnpath.is_file():
raise Exception(reason="File {} not found".format(rawfn))
# Open and read what is in file already
async with aiofiles.open(fnpath, mode="r", encoding="utf-8") as af:
print("Reading lines!")
while True:
line = await af.readline()
print(line, end="")
async def main(*args):
tasks = [follow(name) for name in args]
await asyncio.gather(*tasks)
# await follow("one.txt")
if __name__ == "__main__":
args = sys.argv[1:]
args = ["one.txt", "two.txt"]
asyncio.run(main(*args))
# loop = asyncio.get_event_loop()
# asyncio.ensure_future(main(*args))
# loop.run_forever()