Stabilizza barcode e UDC non scaffalate
This commit is contained in:
@@ -19,6 +19,7 @@ from typing import Any, Callable, Optional
|
||||
import customtkinter as ctk
|
||||
|
||||
from async_loop_singleton import get_global_loop
|
||||
from runtime_support import log_exception
|
||||
from version_info import module_version
|
||||
|
||||
__version__ = module_version(__name__)
|
||||
@@ -128,21 +129,53 @@ class AsyncRunner:
|
||||
busy.show(message)
|
||||
fut = asyncio.run_coroutine_threadsafe(awaitable, self.loop)
|
||||
|
||||
def _widget_alive() -> bool:
|
||||
try:
|
||||
return bool(self.widget.winfo_exists())
|
||||
except tk.TclError:
|
||||
return False
|
||||
|
||||
def _dispatch_success(res: Any) -> None:
|
||||
try:
|
||||
on_success(res)
|
||||
except BaseException as ex:
|
||||
log_exception(__name__, ex, context="AsyncRunner on_success")
|
||||
|
||||
def _dispatch_error(ex: BaseException) -> None:
|
||||
if on_error:
|
||||
try:
|
||||
on_error(ex)
|
||||
except BaseException as callback_ex:
|
||||
log_exception(__name__, callback_ex, context="AsyncRunner on_error")
|
||||
else:
|
||||
log_exception(__name__, ex, context="AsyncRunner unhandled error")
|
||||
|
||||
def _poll():
|
||||
if not _widget_alive():
|
||||
return
|
||||
if fut.done():
|
||||
if busy:
|
||||
busy.hide()
|
||||
try:
|
||||
busy.hide()
|
||||
except Exception as ex:
|
||||
log_exception(__name__, ex, context="AsyncRunner hide busy")
|
||||
try:
|
||||
res = fut.result()
|
||||
except BaseException as ex:
|
||||
if on_error:
|
||||
self.widget.after(0, lambda e=ex: on_error(e))
|
||||
else:
|
||||
print("[AsyncRunner] Unhandled error:", repr(ex))
|
||||
try:
|
||||
self.widget.after(0, lambda e=ex: _dispatch_error(e))
|
||||
except tk.TclError:
|
||||
log_exception(__name__, ex, context="AsyncRunner error after destroyed")
|
||||
else:
|
||||
self.widget.after(0, lambda r=res: on_success(r))
|
||||
try:
|
||||
self.widget.after(0, lambda r=res: _dispatch_success(r))
|
||||
except tk.TclError as ex:
|
||||
log_exception(__name__, ex, context="AsyncRunner success after destroyed")
|
||||
else:
|
||||
self.widget.after(60, _poll)
|
||||
try:
|
||||
self.widget.after(60, _poll)
|
||||
except tk.TclError:
|
||||
return
|
||||
|
||||
_poll()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user