I want to spawn a process and get the process-object for further processing. But I got an error when I use arguments. What am I doing wrong?
Here is my script:
import trio
from subprocess import PIPE
VAR = {'prg': None}
async def main():
async with trio.open_nursery() as nrs:
VAR['prg'] = await nrs.start(trio.run_process, 'cvlc -'.split(), stdin=PIPE)
nrs.start_soon(test)
async def test():
while VAR['prg'] is None:
await trio.sleep(0.1)
print(dir(VAR['prg']))
print(type(VAR['prg'].stdin))
await trio.sleep(2)
VAR['prg'].terminate()
if __name__ == '__main__':
trio.run(main)
And this is the error-message:
Traceback (most recent call last):
File "/media/DEV/mit_trio_loop/Test-run_process_01.py", line 28, in <module>
trio.run(main)
File "/home/tester/.local/lib/python3.10/site-packages/trio/_core/_run.py", line 2010, in run
raise runner.main_task_outcome.error
File "/media/DEV/mit_trio_loop/Test-run_process_01.py", line 16, in main
VAR['prg'] = await nrs.start(trio.run_process, 'cvlc -'.split(), stdin=PIPE)
TypeError: Nursery.start() got an unexpected keyword argument 'stdin'
I'm stuck here. Can anyone help?
Use functools.partial
to encapsulate the arguments. nursery.start
doesn't allow them.
VAR['prg'] = await nrs.start(functools.partial(trio.run_process, 'cvlc -'.split(), stdin=PIPE))