comparison src/light9/blender/asyncio_thread.py @ 2432:b8a408caf115

start blender sync
author drewp@bigasterisk.com
date Tue, 28 May 2024 15:35:12 -0700
parents
children
comparison
equal deleted inserted replaced
2431:d1946cb32121 2432:b8a408caf115
1 import asyncio
2 from threading import Thread
3 from typing import Coroutine
4
5
6 def startLoopInThread(task: Coroutine) -> asyncio.AbstractEventLoop:
7
8 def start_background_loop(loop: asyncio.AbstractEventLoop) -> None:
9 asyncio.set_event_loop(loop)
10 loop.run_forever()
11
12 loop = asyncio.new_event_loop()
13 t = Thread(target=start_background_loop, args=(loop,), daemon=True)
14 t.start()
15 asyncio.run_coroutine_threadsafe(task, loop)
16 return loop