Make print() use a single write() call

オープン
#161,934 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
22/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

The builtin print() lives in Python/bltinmodule.c (builtin_print_impl), which currently issues separate writes for each argument, the separator and end. Read that function first, then the existing tests in Lib/test/test_builtin.py covering print to see the expected partial-output and flush behaviour. Done means one buffered write per call, partial output preserved when str() raises, plus tests for the atomicity and error paths.

索引モデルが issue の本文から書いたものです。

説明

interpreter-core topic-IO type-feature
Feature or enhancement

Currently, print("a", "b") performs four separate writes:

file.write("a")
file.write(" ")
file.write("b")
file.write("\n")

The proposed behavior is equivalent to:

file.write("a b\n")

The main motivation is to reduce interleaving between concurrent print() calls. For example, two threads printing separate messages can currently produce msg1msg2\n\n. Atomicity would still depend on the underlying stream.

Reducing the number of calls can also improve performance, particularly for streams with expensive write() methods, such as IDLE’s output stream.

The implementation should preserve partial output when converting an argument with str() raises: write the parts collected so far, without appending end, and propagate the exception. If flush=True, flush that partial output as well.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/make-print-use-a-single-write-call/109886

Linked PRs
  • gh-161936
主要言語
Python
スター
78.2k
フォーク
36.6k
平均マージ
19時間 57分
マージ済み PR(30日)
630

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。