Skip to content

Allow Path in create_subprocess_* #4159

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

Merged
merged 8 commits into from
Jun 4, 2020
Merged

Allow Path in create_subprocess_* #4159

merged 8 commits into from
Jun 4, 2020

Conversation

Dreamsorcerer
Copy link
Contributor

No description provided.

@srittau
Copy link
Collaborator

srittau commented Jun 3, 2020

I am sorry for not checking earlier, but BaseEventLoop.subprocess_shell() and BaseEventLoop.subprocess_exec() check explicitly for the arguments to be str or bytes. (At least in Python 3.7.) Did you check that this works? Or are there other loop implementations that support this?

@Dreamsorcerer
Copy link
Contributor Author

Huh, that's weird. I'm running this in Python 3.8:

proc = await asyncio.create_subprocess_exec(
    VAULT_PATH / "analytics.py", VAULT_KEY, WEB_CERT)

Also, for *args, I'm using Paths as in this code:

    proc = await asyncio.create_subprocess_exec(
        "openssl", "req", "-new", "-x509", "-newkey", "ec",
        ...
       "-nodes", "-out", cert_path, "-keyout", key_path)

I'm just using the default asyncio implementation in an aiohttp app.

@srittau
Copy link
Collaborator

srittau commented Jun 4, 2020

It's possible that asyncio provides its own loops that support this. Could you add a comment to the two arguments to the effect that not all loops support PathLike arguments, just to clarify this?

@Dreamsorcerer
Copy link
Contributor Author

Dreamsorcerer commented Jun 4, 2020

OK, digging in a little closer, if you follow the function calls through here:
https://github.com/python/cpython/blob/232dda6cbc10860328a83517a6e3ea238ff4147f/Lib/asyncio/base_events.py#L1634
It appears to just pass the arguments to Popen.

That then converts the Path objects here:
https://github.com/python/cpython/blob/232dda6cbc10860328a83517a6e3ea238ff4147f/Lib/subprocess.py#L1350

However, it only does so if shell=False, so I was mistaken to add this to the shell version.

@Dreamsorcerer
Copy link
Contributor Author

However, I see that there is an explicit check for str/bytes in the 3.7 branch. I'll make it conditional on 3.8 then.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 5b66868 into python:master Jun 4, 2020
vishalkuo pushed a commit to vishalkuo/typeshed that referenced this pull request Jun 26, 2020
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 this pull request may close these issues.

2 participants