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
I have made a script to capture stdin, stderr and put the messages into ui.log().
All is working well, except on first page reload (...no more after), I receive this error message:
Client has been deleted but is still being used. This is most likely a bug in your application code. See https://github.com/zauberzeug/nicegui/issues/3028 for more information.
Stack (most recent call last):
File "C:\Program Files\Python311\Lib\threading.py", line 1002, in _bootstrap
self._bootstrap_inner()
File "C:\Program Files\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
self.run()
File "C:\Program Files\Python311\Lib\threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\src\utl\console.py", line 74, in read_queue
self.log_ui.push(log_message)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\elements\log.py", line 26, in push
Label(text)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\elements\label.py", line 13, in __init__
super().__init__(tag='div', text=text)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\elements\mixins\text_element.py", line 14, in __init__
super().__init__(**kwargs)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\element.py", line 77, in __init__
self.client.outbox.enqueue_update(self)
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\outbox.py", line 50, in enqueue_update
self.client.check_existence()
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\client.py", line 346, in check_existence
helpers.warn_once('Client has been deleted but is still being used. '
File "C:\Users\zak-4\PycharmProjects\WLEDVideoSync\.venv\Lib\site-packages\nicegui\helpers.py", line 20, in warn_once
log.warning(message, stack_info=stack_info)
Had take a look to the provided link, but not really related for my case ..??!!
Here is the script :
fromniceguiimportuiimportsysimportmultiprocessingimportthreadingimporttimeclassConsoleCapture:
"""Captures and displays console output in a NiceGUI UI. Redirects stdout and stderr to a queue, which is then displayed in an ui.log element. Provides options for UI customization and restoring the original console output streams. """def__init__(self, show_console=False, text_color='text-white', bg_color='bg-black'):
"""Initialize the ConsoleCapture. Sets up console capturing by redirecting stdout and stderr, initializing the UI if requested, and starting a background thread to process captured output. """self.original_stdout=sys.stdoutself.original_stderr=sys.stderrself.text_color=text_colorself.bg_color=bg_colorifshow_console:
self.setup_ui()
else:
self.log_ui=Noneself.log_queue=multiprocessing.Queue()
sys.stdout=selfsys.stderr=self# Start a background thread to read from the queueself.running=Truethreading.Thread(target=self.read_queue, daemon=True).start()
defsetup_ui(self):
"""Set up the UI for the console output. Creates and configures an ui.log element to display captured console output, applying specified styling classes. """self.log_ui=ui.log()
self.log_ui.classes(f'console-output w-full h-30 {self.bg_color}{self.text_color}')
defwrite(self, text):
"""Override sys.stdout and sys.stderr to send output to the queue and original streams."""iftext.strip():
self.log_queue.put(text.strip()) # Send to the queue# Write to the original stdout or stderrif"Error"intext:
self.original_stderr.write(text)
else:
self.original_stdout.write(text)
defflush(self):
"""Flush method for compatibility."""passdefrestore(self):
"""Restore original stdout and stderr."""sys.stdout=self.original_stdoutsys.stderr=self.original_stderrself.running=Falsedefread_queue(self):
"""Continuously read from the queue and update the UI log."""whileself.running:
try:
whilenotself.log_queue.empty():
log_message=self.log_queue.get()
ifself.log_uiisnotNone:
self.log_ui.push(log_message)
exceptExceptionase:
self.original_stderr.write(f"Queue reading error: {e}\n")
time.sleep(0.1) # Prevent busy waitingif__name__in"__main__":
# NiceGUI app@ui.page('/')asyncdefmain_page():
capture=ConsoleCapture(show_console=False)
withui.column():
ui.button('Print Message', on_click=lambda: print('Hello from stdout!'))
ui.button('Raise Exception', on_click=lambda: 1/0)
ui.button('Send Custom Log', on_click=lambda: capture.log_queue.put("[INFO] Custom log message"))
ui.button('Restore Console', on_click=capture.restore)
capture.setup_ui()
ui.context.client.on_disconnect(lambda: print('client disconnected'))
ui.context.client.on_disconnect(lambda: print('client connected'))
ui.run(reload=False)
Thanks
The text was updated successfully, but these errors were encountered:
Description
Info : Win 11, Python 3.12, NiceGUI 2.12.1
I have made a script to capture stdin, stderr and put the messages into ui.log().
All is working well, except on first page reload (...no more after), I receive this error message:
Had take a look to the provided link, but not really related for my case ..??!!
Here is the script :
Thanks
The text was updated successfully, but these errors were encountered: