Skip to content

python: exit with the exit code returned by main_function - #1644

Open
lf- wants to merge 1 commit into
meta:mainfrom
mercury:jade/push-uqywtrkxvuuw
Open

lf- wants to merge 1 commit into
meta:mainfrom
mercury:jade/push-uqywtrkxvuuw

Conversation

@lf-

@lf- lf- commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

my agent and I got really surprised by main_function not working like [project.scripts] in pyproject.toml. we assumed that the program would exit with the return code of the declared main function, however, it is instead surprisingly eaten.

i usually write stuff like this (c.f. https://docs.python.org/3/library/__main__.html#idiomatic-usage), and
thus i expect main to always return an int, which is why main_function not accepting an int is surprising to me:

import sys

def main():
    return 1

if __name__ == "__main__":
    sys.exit(main())

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2026
lf- added a commit to mercury/buck2 that referenced this pull request Nov 24, 2026
my agent and I got really surprised by main_function not working like
[project.scripts] in pyproject.toml. we assumed that the program would
exit with the return code of the declared main function, however, it is
instead surprisingly eaten.

upstream-pr: meta#1644
@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D134119823. (Because this pull request was imported automatically, there will not be any future comments.)

@lf-
lf- force-pushed the jade/push-uqywtrkxvuuw branch 2 times, most recently from 46314a8 to dfddb0c Compare November 25, 2026 18:22
my agent and I got really surprised by main_function not working like
[project.scripts] in pyproject.toml. we assumed that the program would
exit with the return code of the declared main function, however, it is
instead surprisingly eaten.

i usually write stuff like this (c.f.
https://docs.python.org/3/library/__main__.html#idiomatic-usage), and
thus i expect `main` to always return an int, which is *why*
`main_function` not accepting an int is surprising to me:

```
import sys

def main():
    return 1

if __name__ == "__main__":
    sys.exit(main())
```
@lf-
lf- force-pushed the jade/push-uqywtrkxvuuw branch from dfddb0c to 4e82782 Compare November 26, 2026 20:32
lf- added a commit to mercury/buck2 that referenced this pull request Nov 26, 2026
my agent and I got really surprised by main_function not working like
[project.scripts] in pyproject.toml. we assumed that the program would
exit with the return code of the declared main function, however, it is
instead surprisingly eaten.

upstream-pr: meta#1644
lf- added a commit to mercury/buck2 that referenced this pull request Nov 26, 2026
my agent and I got really surprised by main_function not working like
[project.scripts] in pyproject.toml. we assumed that the program would
exit with the return code of the declared main function, however, it is
instead surprisingly eaten.

upstream-pr: meta#1644

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant