Skip to content

Comments

Clarify stdout flush behavior for newline characters inside a single print() call#1

Open
Vemulakonda559 wants to merge 639 commits intomainfrom
Vemulakonda559-patch-1
Open

Clarify stdout flush behavior for newline characters inside a single print() call#1
Vemulakonda559 wants to merge 639 commits intomainfrom
Vemulakonda559-patch-1

Conversation

@Vemulakonda559
Copy link
Owner

This PR adds a note to the print() documentation to clarify how Python’s stdout buffering works with newline (\n) characters inside a single print call.

Motivation:

Current documentation mentions that flush() is implied for writes containing newlines.

However, it does not explain that Python flushes only after the entire write operation, not mid-string.

This can confuse users coming from C, who expect a flush at each newline, and developers writing scripts that rely on immediate output for progress indicators or CLI feedback.

What’s added:

A .. note:: block explaining that stdout behavior depends on the environment (TTY vs redirected stdout).

Guidance on explicitly flushing with flush=True or sys.stdout.flush().

Mention of python -u for unbuffered output.

A short example demonstrating the behavior.

Impact:

Improves clarity for learners and developers.

Aligns documentation with actual behavior across different environments.

Not a behavior change — documentation-only PR.

Related Issue:

Addresses issue python#141395

savannahostrowski and others added 30 commits December 12, 2025 21:23
…ic release artifacts (python#142405)

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
…2290)

This roughly follows what was done for dictobject to make a lock-free
lookup operation. With this change, the set contains operation scales much
better when used from multiple-threads. The frozenset contains performance
seems unchanged (as already lock-free).

Summary of changes:

* refactor set_lookkey() into set_do_lookup() which now takes a function
  pointer that does the entry comparison. This is similar to dictobject and
  do_lookup(). In an optimized build, the comparison function is inlined and
  there should be no performance cost to this.

* change set_do_lookup() to return a status separately from the entry value

* add set_compare_frozenset() and use if the object is a frozenset. For the
  free-threaded build, this avoids some overhead (locking, atomic operations,
  incref/decref on key)

* use FT_ATOMIC_* macros as needed for atomic loads and stores

* use a deferred free on the set table array, if shared (only on free-threaded
  build, normal build always does an immediate free)

* for free-threaded build, use explicit for loop to zero the table, rather than memcpy()

* when mutating the set, assign so->table to NULL while the change is a
  happening. Assign the real table array after the change is done.
…ython#142658)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
* Commit

* Skip if tzdata version does not match

* Mark as generated

* Update to 2025.3
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Maciej Olko <maciej.olko@affirm.com>
…thon#142592)

Co-authored-by: Pablo Galindo Salgado <pablogsal@gmail.com>
…onGH-142667)

The variable was previously used, but became unused after 133138a.

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
…#127931)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ython#142676)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
hugovk and others added 8 commits December 30, 2025 14:31
…,in}dent`` (python#131924)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
If you are building with `--with-thread-sanitizer` and don't use the
suppression file, then running configure will report a thread leak.

Call `pthread_join()` to avoid the thread leak.
)

The error return code doesn't need to be mutable state on the SSLSocket.
This simplifes thread-safety and avoids potential reentrancy issues.
…Handler (pythonGH-137860)

Add RegisterEventSource(), DeregisterEventSource(), ReportEvent()
and a number of EVENTLOG_* constants to _winapi.
…erpreter.ExecutionFailed` (python#141723)

Remove documentation for inexistant `concurrent.futures.interpreter.ExecutionFailed`
and replace its occurrences by `concurrent.interpreters.ExecutionFailed` since this
is the documented exception.
@Vemulakonda559 Vemulakonda559 force-pushed the Vemulakonda559-patch-1 branch from 2d66675 to c3c6dab Compare January 1, 2026 05:09
picnixz and others added 20 commits January 1, 2026 11:55
…O, _METHOD_DESCRIPTOR_O} (pythonGH-143330)

Co-authored-by: Ken Jin <kenjin4096@gmail.com>
…T` (pythonGH-143320)

Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
…ystem (python#142360)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This PR adds a note to the print() documentation to clarify how Python’s stdout buffering works with newline (\n) characters inside a single print call.

Motivation:

Current documentation mentions that flush() is implied for writes containing newlines.

However, it does not explain that Python flushes only after the entire write operation, not mid-string.

This can confuse users coming from C, who expect a flush at each newline, and developers writing scripts that rely on immediate output for progress indicators or CLI feedback.


What’s added:

A .. note:: block explaining that stdout behavior depends on the environment (TTY vs redirected stdout).

Guidance on explicitly flushing with flush=True or sys.stdout.flush().

Mention of python -u for unbuffered output.

A short example demonstrating the behavior.


Impact:

Improves clarity for learners and developers.

Aligns documentation with actual behavior across different environments.

Not a behavior change — documentation-only PR.


Related Issue:

Addresses issue python#141395
Removed duplicate text and improved clarity in the note about stdout flushing behavior.
Removed redundant sentence about output buffering.
Removed unnecessary comments about string flushing in print.
Remove extra blank lines and fix indentation for versionchanged directive.
Reformat output buffering explanation for clarity.
@Vemulakonda559 Vemulakonda559 force-pushed the Vemulakonda559-patch-1 branch from c3c6dab to 0ece9e0 Compare January 2, 2026 03:55
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.