Update leenkx/blender/lnx/handlers.py

This commit is contained in:
LeenkxTeam 2025-04-11 21:16:04 +00:00
parent c08e1d3835
commit 06319131fd

View File

@ -132,6 +132,7 @@ def always() -> float:
return 0.5 return 0.5
def poll_threads() -> float: def poll_threads() -> float:
"""Polls the thread callback queue and if a thread has finished, it """Polls the thread callback queue and if a thread has finished, it
is joined with the main thread and the corresponding callback is is joined with the main thread and the corresponding callback is
@ -141,19 +142,25 @@ def poll_threads() -> float:
thread, callback = make.thread_callback_queue.get(block=False) thread, callback = make.thread_callback_queue.get(block=False)
except queue.Empty: except queue.Empty:
return 0.25 return 0.25
if thread.is_alive():
thread.join()
try: try:
make.thread_callback_queue.put((thread, callback), block=False)
except queue.Full:
return 0.5
return 0.1
else:
try:
thread.join()
callback() callback()
except Exception as e: except Exception as e:
# If there is an exception, we can no longer return the time to # If there is an exception, we can no longer return the time to
# the next call to this polling function, so to keep it running # the next call to this polling function, so to keep it running
# we re-register it and then raise the original exception. # we re-register it and then raise the original exception.
try:
bpy.app.timers.unregister(poll_threads) bpy.app.timers.unregister(poll_threads)
except ValueError:
pass
bpy.app.timers.register(poll_threads, first_interval=0.01, persistent=True) bpy.app.timers.register(poll_threads, first_interval=0.01, persistent=True)
raise e
# Quickly check if another thread has finished # Quickly check if another thread has finished
return 0.01 return 0.01