Rockhopper-Technologies / enlighten

Enlighten Progress Bar for Python Console Apps
https://python-enlighten.readthedocs.io
Mozilla Public License 2.0
416 stars 25 forks source link

Incomplete flushing of output buffers under pyinstaller on WIndows #21

Closed avylove closed 4 years ago

avylove commented 4 years ago

Describe the bug Under pyinstaller output buffers are mangled in a way where some escape codes are written in plain text to the screen at the end of the program

To Reproduce

Create script:

import time
import enlighten

manager = enlighten.get_manager()
ticks = manager.counter(total=100, desc='Ticks', unit='ticks')

for num in range(100):
    time.sleep(0.01)
    ticks.update()
    print(num)

manager.stop()

Build and run:

c:> pyinstaller.exe --hidden-import=jinxed.terminfo.vtwin10 --onefile test.py
c:> dist\test.exe

Environment (please complete the following information):

Additional context

This may be triggered by something called by Manager.stop(). It does not appear to happen a simple test case in jinxed and does occur if Manager.stop() isn't called. The output seems to be flushed to the screen after the program has terminated.

avylove commented 4 years ago

@camprevail, I looked at this for a while. They seem to be something with the output buffering in pyinstaller. Can you reach out to them to see?

camprevail commented 4 years ago

yeah I'll open an issue for it

avylove commented 4 years ago

Thanks! Please reference this issue or link here.

avylove commented 4 years ago

https://github.com/pyinstaller/pyinstaller/issues/4908 opened on Jun 1, closed Jun 13 after being unable to reproduce

avylove commented 4 years ago

Root cause was Pyinstaller didn't flush stdout and stderr before invoking atexit. This was fixed in https://github.com/pyinstaller/pyinstaller/commit/d8e4621df273233ca379222e9a9425af0937fb3a, released in 4.0

Enlighten shouldn't be depending on this behavior, so the flushing was improved in ccf77ff35e76dc8303fd2ac686e7029a07e6a8c4. It will go out with the next release

Jinxed should also flush the buffers before resetting the console mode. That was added in https://github.com/Rockhopper-Technologies/jinxed/commit/aca28e7036c73f03d6a73a54386952c5f3a4611f, released in 1.0.1

Any of these independently will resolve it. Let me know if you have any additional issues.