Skip to content

gh-144503: Pass sys.argv via a route less limited by single command line argument length#144508

Open
sjoerdjob wants to merge 6 commits intopython:mainfrom
sjoerdjob:issue-144503-multiprocessing-forkserver-arglen
Open

gh-144503: Pass sys.argv via a route less limited by single command line argument length#144508
sjoerdjob wants to merge 6 commits intopython:mainfrom
sjoerdjob:issue-144503-multiprocessing-forkserver-arglen

Conversation

@sjoerdjob
Copy link
Copy Markdown

@sjoerdjob sjoerdjob commented Feb 5, 2026

The maximum length of a single command line argument is more restricted than the total size of all command line arguments together.

The maximum length of a single command line argument is more restricted
than the total size of all command line arguments together.
@sjoerdjob sjoerdjob requested a review from gpshead as a code owner February 5, 2026 15:15
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Feb 5, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Feb 5, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

The `resource` module is not available in a WASI environment.
@sjoerdjob sjoerdjob force-pushed the issue-144503-multiprocessing-forkserver-arglen branch from c375314 to 0507aa0 Compare February 5, 2026 15:35
else:
authkey = b''

if preload:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm kind-of inclined to think that this logic should be in _handle_preload, but I'm not sure how to combine that with the tests that were introduced in gh-141859.

…ad of argv

The allowed size for argv is limited, while the amount of data that can
be sent over a pipe is virtually unlimited.
main_kws = {}
if self._preload_modules:
data = spawn.get_preparation_data('ignore')
if 'sys_path' in data:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The if ... in data have been removed, because a cursory reading of get_preparation_data shows that the sys_path, sys_argv are always present in the returned dictionary.

The init_main_from_path is not always present, but the default argument in _handle_preload is None, so I think using that same value here is fine.

Similarly to on_error: this was checking if it was equal to the default value of _handle_preload, and if so, would not pass it. If the default value of _handle_preload would be changed, and this statement here would not be, that would cause an inconsistency. I think it's better to just always pass the value here to prevent future drift.

@sjoerdjob sjoerdjob changed the title gh-144503: Pass sys.argv as separate command line arguments. gh-144503: Pass sys.argv via a route less limited by single command line argument length Feb 9, 2026
- Use buffered os.fdopen() for both writing and reading the init pipe
  so that preload payloads larger than PIPE_BUF are written and read
  fully. A bare os.write() may short-write large buffers.
- Use data.get() for preparation-data keys rather than direct indexing
  to avoid coupling to spawn.get_preparation_data() internals.
main_kws['on_error'] = self._preload_on_error
preload_kwargs = {
"preload": self._preload_modules,
"sys_path": data.get("sys_path"),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This data.get("sys_path") can just be data["sys_path"]. I feel quite certain that there is no flow through get_preparation_data where the key "sys_path" is not in the returned dictionary.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants