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

Handle non-PTY case for modal shell and modal container exec #2626

Merged
merged 9 commits into from
Dec 11, 2024

Conversation

aksh-at
Copy link
Contributor

@aksh-at aksh-at commented Dec 9, 2024

Resolves CLI-239

modal container exec now checks stdout.isatty() to determine whether to run in PTY mode or not. If not, it uses StreamType.STDOUT to write output directly to stdout. This means that you can now do this:

modal shell -c 'uv pip list' > env.txt

It didn't make sense for ContainerProcess.attach() to support pty=False, so I removed that option and made it a deprecation_error directly.

Added a test for modal container exec since none existed, but it's a bit tricky to test PTY behavior directly because of how we run this. Tested some basic cases manually:

image

Depends on #2624.

Backward/forward compatibility checks

Check these boxes or delete any item (or this section) if not relevant for this PR.

  • Client+Server: this change is compatible with old servers
  • Client forward compatibility: this change ensures client can accept data intended for later versions of itself

Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.


Changelog

  • modal container exec and modal shell now work correctly even when a pseudoterminal (PTY) is not present. This means, for example, that you can pipe the output of these commands to a file:

    modal shell -c 'uv pip list' > env.txt

@aksh-at aksh-at requested review from mwaskom and pawalt December 9, 2024 00:44
Copy link
Member

@pawalt pawalt left a comment

Choose a reason for hiding this comment

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

Nice!

modal/cli/run.py Outdated Show resolved Hide resolved
if pty:
await _ContainerProcess(res.exec_id, client).attach()
else:
# TODO: redirect stderr to its own stream?
Copy link
Member

Choose a reason for hiding this comment

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

Yeah maybe it should go in its own stream. The API is implemented like this to match subprocess, but we could easily add StreamType.STDERR.

@aksh-at aksh-at force-pushed the akshat/fix-no-pty-container-exec branch from cb169b6 to e537fd3 Compare December 9, 2024 23:06
@aksh-at aksh-at merged commit 98ef292 into main Dec 11, 2024
22 checks passed
@aksh-at aksh-at deleted the akshat/fix-no-pty-container-exec branch December 11, 2024 01:03
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