Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Can't print to stdout after calling finish unless calling it twice #120

Copy link
Copy link

Description

@Preston-Landers
Issue body actions

Description

When using redirect_stdout=True, attempts to print() after finishing or otherwise write to sys.stdout are lost (not printed to console), unless finish() is called twice. It seems only the second finish call actually restores the old stdout.

Doesn't matter whether using context wrapper or not. If using context wrapper, you must call finish() inside the context to get stdout restored. If not using context wrapper, you must call finish twice.

Following example illustrates. Running this as is, you should see FINISH printed. If you remove that second p.finish() call, you won't see FINISH printed.

Code

import progressbar
import time
import sys

m = 24514315
p = progressbar.ProgressBar(
    widgets=[progressbar.Percentage(), progressbar.Bar()],
    max_value=m,
    redirect_stdout=True,
)

print("START")

for x in range(0, m, 8192):
    time.sleep(0.0001)
    p.update(x)

p.finish()
p.finish()   # why does it need another finish here?

# with progressbar.ProgressBar(
#         widgets=[progressbar.Percentage(), progressbar.Bar()],
#         max_value=m,
#         redirect_stdout=True) as p:
#     for x in range(0, m, 8192):
#         time.sleep(0.0001)
#         p.update(x)
#
#     p.finish()

print("FINISHED")

Versions

  • Python version: 3.6.1 (x86-64)
  • Python distribution/environment: CPython
  • Operating System: Windows 10 x86-64
  • Package version: 3.20.2
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.