Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading a file from standardinput using ainput #28

Closed
srbcheema1 opened this issue Jul 12, 2018 · 2 comments
Closed

Reading a file from standardinput using ainput #28

srbcheema1 opened this issue Jul 12, 2018 · 2 comments

Comments

@srbcheema1
Copy link

srbcheema1 commented Jul 12, 2018

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 the terminal. normally it works fine. But it doesn't work for reading data from a 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.
Thanks in advance :)

Regards,
Sarbjit Singh

@vxgmichel
Copy link
Owner

vxgmichel commented Jul 12, 2018

Thanks for the report @srbcheema1,

It turns out this issue has already been fixed in PR #25. It became visible in version 0.1.9 that I just released. Run pip3 install -U aioconsole and you should be good to go :)

Repository owner deleted a comment from srbcheema1 Jul 12, 2018
@srbcheema1
Copy link
Author

srbcheema1 commented Jul 12, 2018

it worked :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants