我写了一个适用于asyncio的代码。在该代码中,我必须使用./check.py < file.txt
从标准输入读取文件
我可以从终端输入。通常它工作正常。
但这不适用于从标准输入中读取文件中的数据。
#!/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())
通常它的作用就像
$ ./check.py
4
got 4
5
got 5
但是当直接从文件读取时,我遇到此日志:
$ ./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.
无法了解为什么它的行为有所不同?
我想使用协同程序读取./check.py < file.txt
之类的文件。
答案 0 :(得分:1)
a bug中已修复的是aioconsole v0.1.9。
只需运行以下命令即可获取最新版本:
System.ArgumentNullException: Value cannot be null.
Parameter name: input
at System.Guid.Parse(String input)
at Archetype.PropertyEditors.ArchetypePropertyEditor.ArchetypePropertyValueEditor.ConvertEditorToDb(ContentPropertyData editorValue, Object currentValue)
2018-07-12 08:28:56,429 [P5580/D2/T81] ERROR Archetype.PropertyEditors.ArchetypePropertyEditor+ArchetypePropertyValueEditor - Value cannot be null.