Reputation: 610
I have written a code that works on asyncio. In that code I had to read a file from standard input using ./check.py < file.txt
I am able to give input from terminal. normally it works fine.
But it doesn't work for reading data from file from standard input.
#!/usr/bin/env python3.6
import asyncio
from aioconsole import ainput
async def read_input():
while True:
inp = await ainput()
print('got ' + inp)
if (__name__ == "__main__"):
asyncio.get_event_loop().run_until_complete(read_input())
normally it works like
$ ./check.py
4
got 4
5
got 5
But while reading from file directly I face this log:
$ ./check.py < test/test_case
Traceback (most recent call last):
File "./check.py", line 12, in <module>
asyncio.get_event_loop().run_until_complete(read_input())
File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "./check.py", line 8, in read_input
inp = await ainput()
File "/usr/local/lib/python3.6/dist-packages/aioconsole/stream.py", line 156, in ainput
reader, writer = yield from get_standard_streams(loop=loop)
File "/usr/local/lib/python3.6/dist-packages/aioconsole/stream.py", line 144, in get_standard_streams
cache[key] = yield from connection
File "/usr/local/lib/python3.6/dist-packages/aioconsole/stream.py", line 132, in create_standard_streams
reader, writer = yield from future
File "/usr/local/lib/python3.6/dist-packages/aioconsole/stream.py", line 114, in open_pipe_connection
yield from loop.connect_read_pipe(lambda: protocol, pipe_in)
File "/usr/lib/python3.6/asyncio/base_events.py", line 1099, in connect_read_pipe
transport = self._make_read_pipe_transport(pipe, protocol, waiter)
File "/usr/lib/python3.6/asyncio/unix_events.py", line 185, in _make_read_pipe_transport
return _UnixReadPipeTransport(self, pipe, protocol, waiter, extra)
File "/usr/lib/python3.6/asyncio/unix_events.py", line 353, in __init__
raise ValueError("Pipe transport is for pipes/sockets only.")
ValueError: Pipe transport is for pipes/sockets only.
Unable to get why is it behaving differently ?
I want to read a file like ./check.py < file.txt
using coroutines.
Upvotes: 1
Views: 836
Reputation: 13415
It's a bug that has been fixed in aioconsole v0.1.9.
Simply run the following command to get the latest version:
$ pip3 install -U aioconsole
Upvotes: 1