You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When the manager still exists but the enlighten.Counter()'s have all been .close(clear=True) there's a crash that can happen inside resize handler
I tried to extract a minimal repro but wasn't able to ... Logically the crash above happens where the print("crash on resize possible from here in our codebase...") message is printed ...
Found a way to repro -- code updated below
def sleep_and_print():
import time
time.sleep(1)
print("text")
import warnings
warnings.warn("test warning")
if __name__ == "__main__":
import enlighten, time
total = 3
desc = "test"
unit = "step"
enlighten_manager = enlighten.get_manager(
# tried to repro with variations of these -- but can't
# no_resize=False,
# threaded=False,
)
pbar = enlighten_manager.counter(
total=total,
desc=desc,
unit=unit,
leave=False,
)
import concurrent.futures
with concurrent.futures.ThreadPoolExecutor() as executor:
# the work we do while counter exists can either launch threads or not -- added some threads here to try and induce the error
for i in range(total):
future = executor.submit(time.sleep, 1)
future.result()
pbar.update()
print("closing")
pbar.close(clear=True)
print(
"crash on resize seems to happen from here in our codebase, after closing the counter but enlighten_manager still exists ..."
)
with concurrent.futures.ProcessPoolExecutor() as executor:
while True:
future = executor.submit(sleep_and_print)
future.result()
Failure output below
Observations
I seem to have to change two dimensions of the window to trigger the failure ...
setting threaded to True prevents repro'ing ...
print and warnings can be removed and error will still occur
(zephyrus-py3.10) ncohen@m1-max-toast ~/s/z/zephyrus (ben/fix-progressbar-error) [1]> python repro.py
closing
crash on resize seems to happen from here in our codebase, after closing the counter but enlighten_manager still exists ...
text
/Users/ncohen/software/zephr/zephyrus/repro.py:8: UserWarning: test warning
warnings.warn("test warning")
text
text
text
text
text
text
text
text
text
text
text
text
Traceback (most recent call last):
File "/Users/ncohen/software/zephr/zephyrus/repro.py", line 50, in <module>
future.result()
File "/Users/ncohen/.pyenv/versions/3.10.10/lib/python3.10/concurrent/futures/_base.py", line 453, in result
self._condition.wait(timeout)
File "/Users/ncohen/.pyenv/versions/3.10.10/lib/python3.10/threading.py", line 320, in wait
waiter.acquire()
File "/Users/ncohen/Library/Caches/pypoetry/virtualenvs/zephyrus--PefSXhl-py3.10/lib/python3.10/site-packages/enlighten/_manager.py", line 113, in _stage_resize
self._resize_handler()
File "/Users/ncohen/Library/Caches/pypoetry/virtualenvs/zephyrus--PefSXhl-py3.10/lib/python3.10/site-packages/enlighten/_manager.py", line 135, in _resize_handler
buffer.append(u'\n' * (2 * max(self.counters.values())))
ValueError: max() arg is an empty sequence
Environment (please complete the following information):
Enlighten Version: 1.12.2
OS and version: Linux (various) MacOS Sonoma
Console application: [e.g. xterm, cmd, VS Code Terminal] -- iterm2
Special Conditions: [e.g. Running under pyinstaller] -- using matplotlib ...?
Additional context
Sorry I tried to simulate what happens in our environment to repro ... What is above is my attempt to extract a repro ...
Repro above works for me -- for additional context
The full stack trace within our application is actually within matplotlib if that provides any clues ...
(full stack trace minus our application code which calls into pandas plotting) ... Maybe the code in matplotlib is printing something?
importsignalimportsysimporttimeimportenlighten# Create a counter and close itmanager=enlighten.get_manager()
withmanager.counter(leave=False) aspbar:
pass# Resize window and trigger signalsys.stdout.write(f'\033[8;{manager.term.height-2};{manager.term.width}t')
signal.raise_signal(signal.SIGWINCH)
# Wait for errortime.sleep(3)
I think it's an easy fix, but will need to come up with test code. I'll try to have a new release out soon.
Describe the bug
When the manager still exists but the
enlighten.Counter()
's have all been.close(clear=True)
there's a crash that can happen inside resize handlerTo Reproduce
I tried to extract a minimal repro but wasn't able to ... Logically the crash above happens where theprint("crash on resize possible from here in our codebase...")
message is printed ...Found a way to repro -- code updated below
Failure output below
Observations
Environment (please complete the following information):
Additional context
Sorry I tried to simulate what happens in our environment to repro ... What is above is my attempt to extract a repro ...Repro above works for me -- for additional context
The full stack trace within our application is actually within matplotlib if that provides any clues ...
(full stack trace minus our application code which calls into pandas plotting) ... Maybe the code in matplotlib is printing something?
The text was updated successfully, but these errors were encountered: