2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-10-05 07:50:01 +00:00

Cleanly shut down the drawing thread

This commit is contained in:
Jarrod Johnson
2026-10-02 15:23:49 -04:00
parent edaf55ba62
commit 2f3b074380
+17 -1
View File
@@ -16,6 +16,7 @@
# limitations under the License.
import atexit
import asyncio
import base64
import optparse
@@ -1130,7 +1131,10 @@ def draw_node(node, imgdata, errorstr, firstnodename, cwidth, cheight):
def _draw_worker():
while True:
node, imgdata, errorstr, firstnodename, cwidth, cheight = draw_queue.get()
item = draw_queue.get()
if item is None:
break
node, imgdata, errorstr, firstnodename, cwidth, cheight = item
with draw_lock:
_draw_node(node, imgdata, errorstr, firstnodename, cwidth, cheight)
@@ -1161,6 +1165,18 @@ def _draw_node(node, imgdata, errorstr, firstnodename, cwidth, cheight):
draw_thread = threading.Thread(target=_draw_worker, daemon=True)
draw_thread.start()
def close_draw_thread():
global draw_thread
if not draw_thread:
return
mythread = draw_thread
draw_thread = None
if mythread.is_alive():
draw_queue.put(None)
mythread.join(15)
atexit.register(close_draw_thread)
if options.screenshot or options.video:
if not sys.stdout.isatty():
sys.stderr.write(