forked from benrugg/AI-Render
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_queue.py
More file actions
29 lines (20 loc) · 690 Bytes
/
task_queue.py
File metadata and controls
29 lines (20 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import bpy
import queue
from bpy.app.handlers import persistent
# private
execution_queue = queue.Queue()
def execute_queued_functions():
while not execution_queue.empty():
function = execution_queue.get()
function()
return 0.2
# public method
def add(function):
"""Add a function to the task queue, to be executed in the main thread"""
execution_queue.put(function)
def register():
if not bpy.app.timers.is_registered(execute_queued_functions):
bpy.app.timers.register(execute_queued_functions)
def unregister():
if bpy.app.timers.is_registered(execute_queued_functions):
bpy.app.timers.unregister(execute_queued_functions)