aiofile 3.1.1 pipe example not working under Debian stable
I'm running the aiofile 3.1.1 pipe example under Linux (Debian stable, python 3.7). It usually stops with no other output than this:
201021 14:17 ~ srn@lije{1}% python3 /tmp/z.py
Start reader
Start reader
Start writer
C-c C-cExited
Traceback (most recent call last):
File "/tmp/z.py", line 46, in
(Since nothing is output, I give up and press control-C.)
I have made this test several times, trying to use pdb and with other minor changes, and one of the tests yielded a few loop.time() outputs, like this:
Start reader
Start reader
Start writer
1131834.8124811131834.8126551131834.812847
1131834.813134
C-c C-c C-c C-cTraceback (most recent call last):
File "/usr/local/ch-tools3/z.py", line 64, in
Here's /tmp/z.py, which I believe is a verbatim copy of the example from the README:
import os import asyncio from aiofile import AIOFile, Reader, Writer
async def reader(fname): print('Start reader') async with AIOFile(fname, 'r') as afp: while True: # Maximum expected chunk size, must be passed. # Otherwise will be read zero bytes # (because unix pipe has zero size) data = await afp.read(4096) print(data)
async def writer(fname): print('Start writer') async with AIOFile(fname, 'w') as afp: while True: await asyncio.sleep(1) await afp.write('%06f' % loop.time())
async def main(): fifo_name = "/tmp/test.fifo"
if os.path.exists(fifo_name):
os.remove(fifo_name)
os.mkfifo(fifo_name)
# Starting two readers and one writer, but only one reader
# will be reading at the same time.
await asyncio.gather(
reader(fifo_name),
reader(fifo_name),
writer(fifo_name),
)
loop = asyncio.new_event_loop() asyncio.set_event_loop(loop)
try: loop.run_until_complete(main()) finally: # Shutting down and closing file descriptors after interrupt loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() print('Exited')
201021 14:18 ~ srn@lije{1}% uname -a Linux lije 4.19.0-11-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64 GNU/Linux
Please see troubleshooting section in caio