我正在尝试创建一个异步子进程并将一个变量传递给标准输入,但 trio.run_process 和 trio.open_process 都给出了属性错误。它没有指定导致错误的原因。
Traceback (most recent call last):
File "./update.py", line 122, in pkgUpdates
trio.run(self.asetup, password)
File "/home/user/.local/lib/python3.7/site-packages/trio/_core/_run.py", line 1444, in run
raise runner.main_task_outcome.error
File "./update.py", line 65, in asetup
nursery.start_soon(self.upProc, password, 'update')
File "/home/user/.local/lib/python3.7/site-packages/trio/_core/_run.py", line 506, in __aexit__
raise combined_error_from_nursery
File "./update.py", line 75, in upProc
await trio.open_process(['sudo', '-S', 'apt-get', cmd, '-y'],
File "/home/user/.local/lib/python3.7/site-packages/trio/_deprecate.py", line 125, in __getattr__
raise AttributeError(name)
AttributeError: open_process
我也尝试过使用 trio.Process ,stdin=io.BytesIO(password)
但这会产生 io.UnsupportedOperation 错误。仅传递字节也会产生错误。
功能是:
async def upProc(self, password, cmd):
await trio.open_process(['sudo', '-S', 'apt-get', cmd, '-y'],
stdin=password.encode(), capture_stdout=True)
if (cmd == 'update'):
await self.upProc(password, 'upgrade')
return