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

Accept path-like objects for subprocess APIs #328

Closed
achimnol opened this issue Apr 2, 2020 · 0 comments · Fixed by #329
Closed

Accept path-like objects for subprocess APIs #328

achimnol opened this issue Apr 2, 2020 · 0 comments · Fixed by #329

Comments

@achimnol
Copy link
Contributor

achimnol commented Apr 2, 2020

  • uvloop version: 0.14.0
  • Python version: 3.8.2
  • Platform: Linux & macOS
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: yes -- this is what I'm going to report.
import asyncio
from pathlib import Path

async def do():
    p = await asyncio.create_subprocess_exec(Path('/bin/ls'), '-l')
    exit_code = await p.wait()
    print('exited with', exit_code)

asyncio.run(do())

works fine, while

import asyncio
from pathlib import Path
import uvloop

async def do():
    p = await asyncio.create_subprocess_exec(Path('/bin/ls'), '-l')
    exit_code = await p.wait()
    print('exited with', exit_code)

uvloop.install()
asyncio.run(do())

generates an error:

Traceback (most recent call last):
  File "test-sub.py", line 13, in <module>
    asyncio.run(do())
  File "/Users/joongi/.pyenv/versions/3.8.2/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "test-sub.py", line 7, in do
    p = await asyncio.create_subprocess_exec(Path('/bin/ls'), '-l')
  File "/Users/joongi/.pyenv/versions/3.8.2/lib/python3.8/asyncio/subprocess.py", line 236, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "uvloop/loop.pyx", line 2749, in subprocess_exec
  File "uvloop/loop.pyx", line 2707, in __subprocess_run
  File "uvloop/handles/process.pyx", line 596, in uvloop.loop.UVProcessTransport.new
  File "uvloop/handles/process.pyx", line 60, in uvloop.loop.UVProcess._init
  File "uvloop/handles/process.pyx", line 49, in uvloop.loop.UVProcess._init
  File "uvloop/handles/process.pyx", line 247, in uvloop.loop.UVProcess._init_options
  File "uvloop/handles/process.pyx", line 290, in uvloop.loop.UVProcess._init_args
TypeError: all args must be str or bytes

Since Python 3.6 on Linux and Python 3.8 on Windows, the standard subprocess module accepts path-like objects in addition to str and bytes. However, the official documentation for the asyncio's subprocess API does not mention this is also possible in the asyncio's subprocess API, but as internally it uses the subprocess standard module, so it does support path-like objects as demonstrated above.

I believe that uvloop need to replicate this behavior since its goal is a drop-in replacement for asyncio's vanilla loop.

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

Successfully merging a pull request may close this issue.

1 participant